Skip to content

Commit

Permalink
Lints
Browse files Browse the repository at this point in the history
  • Loading branch information
NullVoxPopuli committed Sep 15, 2024
1 parent 401c650 commit 36a54b5
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 21 deletions.
14 changes: 10 additions & 4 deletions packages/repl-sdk/src/compilers/glimmer-js.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { esmsh, jsdelivr } from './cdn.js';
import { esmsh } from './cdn.js';

/**
* @param {import('../types.ts').ResolvedCompilerOptions} config
* @param {import('../types.ts').PublicMethods} api
*/
export async function compiler(config = {}, api) {
export async function compiler(config = {} /*, api */) {
const versions = config.versions || {};

const [
Expand All @@ -13,7 +13,7 @@ export async function compiler(config = {}, api) {
{ default: templateCompiler },
{ Preprocessor },
{ default: MacrosPlugin },
{ MacrosConfig },
,
{ buildPlugin: makeMacrosGlimmerPlugin },
{ default: AdjustImports },
{ default: DebugMacros },
Expand Down Expand Up @@ -63,7 +63,9 @@ export async function compiler(config = {}, api) {
]);

async function transform(text) {
// eslint-disable-next-line
console.log(templateCompiler, templatePlugin);

return babel.transform(text, {
filename: `dynamic-repl.js`,
plugins: [
Expand Down Expand Up @@ -209,6 +211,7 @@ export async function compiler(config = {}, api) {
if (id.startsWith('@ember')) {
return `https://esm.sh/*ember-source/dist/packages/${id}`;
}

if (id.startsWith('@glimmer')) {
return `https://esm.sh/*ember-source/dist/dependencies/${id}.js`;
}
Expand All @@ -222,10 +225,13 @@ export async function compiler(config = {}, api) {
let transformed = await transform({ babel, templatePlugin, templateCompiler }, preprocessed);

let code = transformed.code;

// eslint-disable-next-line
console.log(code);

return code;
},
render: async (element, compiled, extra, compiler) => {
render: async (element, compiled /*, extra, compiler */) => {
element.innerHTML = compiled.toString();
},
};
Expand Down
6 changes: 6 additions & 0 deletions packages/repl-sdk/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,17 @@ export class Compiler {

if (result) return result;
}

// eslint-disable-next-line
console.log('resolve', id);

return `https://esm.sh/*${id}`;
},
// Hook source fetch function
fetch: async (url, options) => {
// eslint-disable-next-line
console.log('fetching url', url);

const response = await fetch(url, options);

return response;
Expand Down Expand Up @@ -108,13 +112,15 @@ export class Compiler {
*/
async #getCompiler(format, flavor) {
const config = this.#resolveFormat(format, flavor);

if (this.#compilerCache.has(config)) {
return this.#compilerCache.get(config);
}

const compiler = await config.compiler(this.optionsFor(format, flavor), this.#nestedPublicAPI);

this.#compilerCache.set(config, compiler);

if (compiler.resolve) {
this.#resolvers.push(compiler.resolve);
}
Expand Down
38 changes: 21 additions & 17 deletions packages/repl-sdk/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
interface PublicMethods {
compile: (format: string, text: string, options?: {
flavor?: string;
fileName?: string;
}) => Promise<HTMLElement>
compile: (
format: string,
text: string,
options?: {
flavor?: string;
fileName?: string;
}
) => Promise<HTMLElement>;

optionsFor: (format: string, flavor?: string) => Omit<CompilerConfig, 'compiler'>
optionsFor: (format: string, flavor?: string) => Omit<CompilerConfig, 'compiler'>;
}
export interface ResolvedCompilerOptions {
importMap: { [importPath: string]: string; };
resolve: { [importPath: string]: unknown; };
importMap: { [importPath: string]: string };
resolve: { [importPath: string]: unknown };
needsLiveMeta?: boolean;
versions: { [packageName: string]: string };
}
Expand Down Expand Up @@ -82,7 +86,7 @@ export interface CompilerConfig {
element: HTMLElement,
defaultExport: any,
extras: { compiled: string } & Record<string, unknown>,
compiler: PublicMethods,
compiler: PublicMethods
) => void;
}>;
}
Expand All @@ -93,26 +97,26 @@ export interface Options {
*
* Thehse will take precedence over the default CDN fallback.
*/
importMap?: { [importPath: string]: string; };
importMap?: { [importPath: string]: string };
/**
* Map of pre-resolved JS values to use as the import map
* These could assume the role of runtime virtual modules.
*
* These will take precedence over the importMap, and implicit CDN fallback.
*/
resolve?: { [importPath: string]: unknown; }
resolve?: { [importPath: string]: unknown };

/**
* Specifies which vesions of dependencies to when pulling from a CDN.
* Defaults to latest.
*/
* Specifies which vesions of dependencies to when pulling from a CDN.
* Defaults to latest.
*/
versions?: { [packageName: string]: string };

formats: {
[fileExtension: string]:
| CompilerConfig
| {
[flavor: string]: CompilerConfig;
};
| CompilerConfig
| {
[flavor: string]: CompilerConfig;
};
};
}

0 comments on commit 36a54b5

Please sign in to comment.