@embroider/vite 0.2.1-unstable.f7656a3 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"resolver.js","sourceRoot":"","sources":["resolver.ts"],"names":[],"mappings":";;;;;AAWA,4BA4EC;AAtFD,0CAAiE;AACjE,uCAA+D;AAC/D,gEAAuC;AACvC,kDAA8B;AAC9B,+BAA+B;AAC/B,uDAAgD;AAGhD,MAAM,KAAK,GAAG,IAAA,eAAS,EAAC,gBAAgB,CAAC,CAAC;AAE1C,SAAgB,QAAQ;IACtB,IAAI,cAAc,GAAG,IAAI,qBAAc,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;IACvD,IAAI,MAAqB,CAAC;IAC1B,IAAI,WAAW,GAA0B,IAAI,GAAG,EAAE,CAAC;IAEnD,OAAO;QACL,IAAI,EAAE,oBAAoB;QAC1B,OAAO,EAAE,KAAK;QAEd,eAAe,CAAC,CAAC;YACf,MAAM,GAAG,CAAC,CAAC;YACX,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,UAAU,EAAE,IAAI,EAAE,EAAE;gBAC5C,KAAK,IAAI,CAAC,EAAE,EAAE,OAAO,CAAC,IAAI,WAAW,EAAE,CAAC;oBACtC,KAAK,IAAI,KAAK,IAAI,OAAO,EAAE,CAAC;wBAC1B,IAAI,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC;4BAC3B,KAAK,CAAC,0BAA0B,EAAE,EAAE,EAAE,IAAI,CAAC,CAAC;4BAC5C,MAAM,CAAC,WAAW,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC;4BACpC,IAAI,CAAC,GAAG,MAAM,CAAC,WAAW,CAAC,aAAa,CAAC,EAAE,CAAC,CAAC;4BAC7C,IAAI,CAAC,EAAE,CAAC;gCACN,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;4BAC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AAC,CAAC,CAAC,WAAW,CAAC,CAAC;IACpD,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import type { Plugin, ViteDevServer } from 'vite';\nimport { virtualContent, ResolverLoader } from '@embroider/core';\nimport { RollupModuleRequest, virtualPrefix } from './request';\nimport assertNever from 'assert-never';\nimport makeDebug from 'debug';\nimport { resolve } from 'path';\nimport { writeStatus } from './esbuild-request';\nimport type { PluginContext } from 'rollup';\n\nconst debug = makeDebug('embroider:vite');\n\nexport function resolver(): Plugin {\n let resolverLoader = new ResolverLoader(process.cwd());\n let server: ViteDevServer;\n let virtualDeps: Map<string, string[]> = new Map();\n\n return {\n name: 'embroider-resolver',\n enforce: 'pre',\n\n configureServer(s) {\n server = s;\n server.watcher.on('all', (_eventName, path) => {\n for (let [id, watches] of virtualDeps) {\n for (let watch of watches) {\n if (path.startsWith(watch)) {\n debug('Invalidate %s because %s', id, path);\n server.moduleGraph.onFileChange(id);\n let m = server.moduleGraph.getModuleById(id);\n if (m) {\n server.reloadModule(m);\n }\n }\n }\n }\n });\n },\n\n async resolveId(source, importer, options) {\n if (options.custom?.depScan) {\n return await observeDepScan(this, source, importer, options);\n }\n\n let request = RollupModuleRequest.from(this, source, importer, options.custom);\n if (!request) {\n // fallthrough to other rollup plugins\n return null;\n }\n let resolution = await resolverLoader.resolver.resolve(request);\n switch (resolution.type) {\n case 'found':\n case 'ignored':\n return resolution.result;\n case 'not_found':\n return null;\n default:\n throw assertNever(resolution);\n }\n },\n load(id) {\n if (id.startsWith(virtualPrefix)) {\n let { pathname } = new URL(id, 'http://example.com');\n let { src, watches } = virtualContent(pathname.slice(virtualPrefix.length + 1), resolverLoader.resolver);\n virtualDeps.set(id, watches);\n server?.watcher.add(watches);\n return src;\n }\n },\n buildEnd() {\n this.emitFile({\n type: 'asset',\n fileName: '@embroider/core/vendor.js',\n source: virtualContent(\n resolve(resolverLoader.resolver.options.engines[0].root, '-embroider-vendor.js'),\n resolverLoader.resolver\n ).src,\n });\n this.emitFile({\n type: 'asset',\n fileName: '@embroider/core/test-support.js',\n source: virtualContent(\n resolve(resolverLoader.resolver.options.engines[0].root, '-embroider-test-support.js'),\n resolverLoader.resolver\n ).src,\n });\n },\n };\n}\n\n// During depscan, we have a wildly different job than during normal\n// usage. Embroider's esbuild resolver plugin replaces this rollup\n// resolver plugin for actually doing resolving, so we don't do any of\n// that. But we are still well-positioned to observe what vite's rollup\n// resolver plugin is doing, and that is important because vite's\n// esbuild depscan plugin will always obscure the results before\n// embroider's esbuild resolver plugin can see them. It obscures the\n// results by marking *both* \"not found\" and \"this is a third-party\n// package\" as \"external: true\". We really care about the difference\n// between the two, since we have fallback behaviors that should apply\n// to \"not found\" that should not apply to successfully discovered\n// third-party packages.\nasync function observeDepScan(context: PluginContext, source: string, importer: string | undefined, options: any) {\n let result = await context.resolve(source, importer, {\n ...options,\n skipSelf: true,\n });\n writeStatus(source, result ? 'found' : 'not_found');\n return result;\n}\n"]}
1
+ {"version":3,"file":"resolver.js","sourceRoot":"","sources":["resolver.ts"],"names":[],"mappings":";;;;;AASA,4BA6BC;AApCD,+BAA4B;AAE5B,0CAAsF;AACtF,uCAAwC;AACxC,uCAA+D;AAC/D,gEAAuC;AAEvC,SAAgB,QAAQ;IACtB,IAAI,eAAe,GAAoB,IAAA,uBAAY,EAAC,IAAA,WAAI,EAAC,IAAA,gCAAyB,EAAC,OAAO,CAAC,GAAG,EAAE,CAAC,EAAE,eAAe,CAAC,CAAC,CAAC;IACrH,IAAI,QAAQ,GAAG,IAAI,eAAQ,CAAC,eAAe,CAAC,CAAC;IAE7C,OAAO;QACL,IAAI,EAAE,oBAAoB;QAC1B,OAAO,EAAE,KAAK;QACd,KAAK,CAAC,SAAS,CAAC,MAAM,EAAE,QAAQ,EAAE,OAAO;YACvC,IAAI,OAAO,GAAG,6BAAmB,CAAC,IAAI,CAAC,MAAM,EAAE,QAAQ,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;YACzE,IAAI,CAAC,OAAO,EAAE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YACN,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,GAAG,EAAE,SAAS,EAAE,CAAC;QAC/C,CAAC;IACH,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import type { PluginContext, ResolveIdResult } from 'rollup';\nimport type { Plugin } from 'vite';\nimport { join } from 'path';\nimport type { Resolution, ResolverFunction, ResolverOptions } from '@embroider/core';\nimport { Resolver, locateEmbroiderWorkingDir, virtualContent } from '@embroider/core';\nimport { readJSONSync } from 'fs-extra';\nimport { RollupModuleRequest, virtualPrefix } from './request';\nimport assertNever from 'assert-never';\n\nexport function resolver(): Plugin {\n let resolverOptions: ResolverOptions = readJSONSync(join(locateEmbroiderWorkingDir(process.cwd()), 'resolver.json'));\n let resolver = new Resolver(resolverOptions);\n\n return {\n name: 'embroider-resolver',\n enforce: 'pre',\n async resolveId(source, importer, options) {\n let request = RollupModuleRequest.from(source, importer, options.custom);\n if (!request) {\n // fallthrough to other rollup plugins\n return null;\n }\n let resolution = await resolver.resolve(request, defaultResolve(this));\n switch (resolution.type) {\n case 'found':\n return resolution.result;\n case 'not_found':\n return null;\n default:\n throw assertNever(resolution);\n }\n },\n load(id) {\n if (id.startsWith(virtualPrefix)) {\n return virtualContent(id.slice(virtualPrefix.length), resolver);\n }\n },\n };\n}\n\nfunction defaultResolve(context: PluginContext): ResolverFunction<RollupModuleRequest, Resolution<ResolveIdResult>> {\n return async (request: RollupModuleRequest) => {\n if (request.isVirtual) {\n return {\n type: 'found',\n result: { id: request.specifier, resolvedBy: request.fromFile },\n };\n }\n let result = await context.resolve(request.specifier, request.fromFile, {\n skipSelf: true,\n custom: {\n embroider: {\n meta: request.meta,\n },\n },\n });\n if (result) {\n return { type: 'found', result };\n } else {\n return { type: 'not_found', err: undefined };\n }\n };\n}\n"]}
package/src/scripts.js CHANGED
@@ -71,15 +71,10 @@ class ScriptOptimizer {
71
71
  this.emitted = new Map();
72
72
  }
73
73
  async optimizedScript(script) {
74
- let fullName = (0, path_1.resolve)(this.rootDir, script.slice(1));
75
- if (!(0, fs_extra_1.existsSync)(fullName)) {
76
- // in prod builds, test-support.js isn't going to exist (for example)
77
- return [];
78
- }
79
74
  // loading these lazily here so they never load in non-production builds.
80
75
  // The node cache will ensures we only load them once.
81
76
  const [Terser, srcURL] = await Promise.all([Promise.resolve().then(() => __importStar(require('terser'))), Promise.resolve().then(() => __importStar(require('source-map-url')))]);
82
- let inCode = (0, fs_extra_1.readFileSync)(fullName, 'utf8');
77
+ let inCode = (0, fs_extra_1.readFileSync)((0, path_1.resolve)(this.rootDir, script.slice(1)), 'utf8');
83
78
  let terserOpts = {};
84
79
  let fileRelativeSourceMapURL;
85
80
  let appRelativeSourceMapURL;
@@ -1 +1 @@
1
- {"version":3,"file":"scripts.js","sourceRoot":"","sources":["scripts.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAaA,0BAuCC;AAlDD,iCAA8B;AAC9B,uCAAkE;AAClE,+BAA+C;AAO/C,MAAM,QAAQ,GAAG,CAAC,mBAAmB,EAAE,yBAAyB,CAAC,CAAC;AAElE,SAAgB,OAAO,CAAC,MAAmD;;IACzE,IAAI,SAA0B,CAAC;IAE/B,mEAAmE;IACnE,IAAI,KAAK,GAAG,CAAC,MAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,OAAO,mCAAI,QAAQ,CAAC;SACtC,MAAM,CAAC,IAAI,CAAC,EAAE,WAAC,OAAA,CAAC,CAAA,MAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,OAAO,0CAAE,QAAQ,CAAC,IAAI,CAAC,CAAA,CAAA,EAAA,CAAC;SAChD,GAAG,CAAC,IAAI,CAAC,EAAE;QACV,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;YACzB,OAAO,IAAI,CAAC;QACd,CAAC;aAAM,CAAC;YACN,OAAO,GAAG,GAAG,IAAI,CAAC;QACpB,CAAC;IACH,CAAC,CAAC,CAAC;IAEL,OAAO;QACL,IAAI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AAS,CAAC,GAAG,CAAC,CAAC;oBACpD,IAAI,aAAa,EAAE,CAAC;wBAClB,SAAS,CAAC,GAAG,GAAG,aAAa,CAAC;oBAChC,CAAC;gBACH,CAAC;YACH,CAAC;YACD,IAAI,OAAO,GAAG,MAAM,CAAC,SAAS,EAAE,CAAC;YACjC,IAAI,CAAC,cAAc,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC;QACpD,CAAC;QACD,OAAO,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC;IACrC,CAAC;CACF","sourcesContent":["import type { Plugin } from 'vite';\nimport type { EmittedFile } from 'rollup';\nimport { JSDOM } from 'jsdom';\nimport { readFileSync, readJSONSync, existsSync } from 'fs-extra';\nimport { dirname, posix, resolve } from 'path';\n\n// This is a type-only import, so it gets compiled away. At runtime, we load\n// terser lazily so it's only loaded for production builds that use it. Don't\n// add any non-type-only imports here.\nimport type { MinifyOptions } from 'terser';\n\nconst defaults = ['/assets/vendor.js', '/assets/test-support.js'];\n\nexport function scripts(params?: { include?: string[]; exclude?: string[] }): Plugin {\n let optimizer: ScriptOptimizer;\n\n // configured names are always interpreted as origin-absolute URLs.\n let names = (params?.include ?? defaults)\n .filter(name => !params?.exclude?.includes(name))\n .map(name => {\n if (name.startsWith('/')) {\n return name;\n } else {\n return '/' + name;\n }\n });\n\n return {\n name: 'embroider-scripts',\n enforce: 'pre',\n\n configResolved(resolvedConfig) {\n optimizer = new ScriptOptimizer(resolvedConfig.root);\n },\n\n async generateBundle() {\n // this hook only runs in `vite build`\n for (let name of names) {\n for (let file of await optimizer.optimizedScript(name)) {\n this.emitFile(file);\n }\n }\n },\n\n transformIndexHtml(htmlIn, context) {\n // we don't do anything in `vite dev`, we only need to work in `vite\n // build`\n if (!context.server) {\n return optimizer.transformHTML(htmlIn);\n }\n },\n };\n}\n\nclass ScriptOptimizer {\n private emitted = new Map<string, string>();\n private transformState:\n | {\n htmlIn: string;\n htmlOut: string;\n parsed: JSDOM;\n }\n | undefined;\n\n constructor(private rootDir: string) {}\n\n async optimizedScript(script: string): Promise<EmittedFile[]> {\n let fullName = resolve(this.rootDir, script.slice(1));\n if (!existsSync(fullName)) {\n // in prod builds, test-support.js isn't going to exist (for example)\n return [];\n }\n\n // loading these lazily here so they never load in non-production builds.\n // The node cache will ensures we only load them once.\n const [Terser, srcURL] = await Promise.all([import('terser'), import('source-map-url')]);\n\n let inCode = readFileSync(fullName, 'utf8');\n let terserOpts: MinifyOptions = {};\n let fileRelativeSourceMapURL;\n let appRelativeSourceMapURL;\n if (srcURL.default.existsIn(inCode)) {\n fileRelativeSourceMapURL = srcURL.default.getFrom(inCode)!;\n appRelativeSourceMapURL = posix.join(dirname(script.slice(1)), fileRelativeSourceMapURL);\n let content;\n try {\n content = readJSONSync(resolve(this.rootDir, appRelativeSourceMapURL));\n } catch (err) {\n // the script refers to a sourcemap that doesn't exist, so we just leave\n // the map out.\n }\n if (content) {\n terserOpts.sourceMap = { content, url: fileRelativeSourceMapURL };\n }\n }\n let { code: outCode, map: outMap } = await Terser.default.minify(inCode, terserOpts);\n let finalFilename = await this.getFingerprintedFilename(script, outCode!);\n let emit: EmittedFile[] = [];\n emit.push({\n type: 'asset',\n fileName: finalFilename.slice(1),\n source: outCode!,\n });\n this.emitted.set(script, finalFilename);\n if (appRelativeSourceMapURL && outMap) {\n emit.push({\n type: 'asset',\n fileName: appRelativeSourceMapURL,\n source: JSON.stringify(outMap, null, 2),\n });\n }\n return emit;\n }\n\n async getFingerprintedFilename(filename: string, content: string): Promise<string> {\n let crypto = await import('crypto');\n let md5 = crypto.createHash('md5');\n md5.update(content);\n let hash = md5.digest('hex');\n let fileParts = filename.split('.');\n fileParts.splice(fileParts.length - 1, 0, hash);\n return fileParts.join('.');\n }\n\n transformHTML(htmlIn: string) {\n if (this.transformState?.htmlIn !== htmlIn) {\n let parsed = new JSDOM(htmlIn);\n let scriptTags = [...parsed.window.document.querySelectorAll('script')] as HTMLScriptElement[];\n for (let scriptTag of scriptTags) {\n if (scriptTag.type !== 'module') {\n let fingerprinted = this.emitted.get(scriptTag.src);\n if (fingerprinted) {\n scriptTag.src = fingerprinted;\n }\n }\n }\n let htmlOut = parsed.serialize();\n this.transformState = { htmlIn, parsed, htmlOut };\n }\n return this.transformState.htmlOut;\n }\n}\n"]}
1
+ {"version":3,"file":"scripts.js","sourceRoot":"","sources":["scripts.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAaA,0BAuCC;AAlDD,iCAA8B;AAC9B,uCAAsD;AACtD,+BAA+C;AAO/C,MAAM,QAAQ,GAAG,CAAC,mBAAmB,EAAE,yBAAyB,CAAC,CAAC;AAElE,SAAgB,OAAO,CAAC,MAAmD;;IACzE,IAAI,SAA0B,CAAC;IAE/B,mEAAmE;IACnE,IAAI,KAAK,GAAG,CAAC,MAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,OAAO,mCAAI,QAAQ,CAAC;SACtC,MAAM,CAAC,IAAI,CAAC,EAAE,WAAC,OAAA,CAAC,CAAA,MAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,OAAO,0CAAE,QAAQ,CAAC,IAAI,CAAC,CAAA,CAAA,EAAA,CAAC;SAChD,GAAG,CAAC,IAAI,CAAC,EAAE;QACV,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;YACzB,OAAO,IAAI,CAAC;QACd,CAAC;aAAM,CAAC;YACN,OAAO,GAAG,GAAG,IAAI,CAAC;QACpB,CAAC;IACH,CAAC,CAAC,CAAC;IAEL,OAAO;QACL,IAAI,EAAE,mBAAmB;QACzB,OAAO,EAAE,KAAK;QAEd,cAAc,CAAC,cAAc;YAC3B,SAAS,GAAG,IAAI,eAAe,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;QACvD,CAAC;QAED,KAAK,CAAC,cAAc;YAClB,sCAAsC;YACtC,KAAK,IAAI,IAAI,IAAI,KAAK,EAAE,CAAC;gBACvB,KAAK,IAA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\nimport { JSDOM } from 'jsdom';\nimport { readFileSync, readJSONSync } from 'fs-extra';\nimport { dirname, posix, resolve } from 'path';\n\n// This is a type-only import, so it gets compiled away. At runtime, we load\n// terser lazily so it's only loaded for production builds that use it. Don't\n// add any non-type-only imports here.\nimport type { MinifyOptions } from 'terser';\n\nconst defaults = ['/assets/vendor.js', '/assets/test-support.js'];\n\nexport function scripts(params?: { include?: string[]; exclude?: string[] }): Plugin {\n let optimizer: ScriptOptimizer;\n\n // configured names are always interpreted as origin-absolute URLs.\n let names = (params?.include ?? defaults)\n .filter(name => !params?.exclude?.includes(name))\n .map(name => {\n if (name.startsWith('/')) {\n return name;\n } else {\n return '/' + name;\n }\n });\n\n return {\n name: 'embroider-scripts',\n enforce: 'pre',\n\n configResolved(resolvedConfig) {\n optimizer = new ScriptOptimizer(resolvedConfig.root);\n },\n\n async generateBundle() {\n // this hook only runs in `vite build`\n for (let name of names) {\n for (let file of await optimizer.optimizedScript(name)) {\n this.emitFile(file);\n }\n }\n },\n\n transformIndexHtml(htmlIn, context) {\n // we don't do anything in `vite dev`, we only need to work in `vite\n // build`\n if (!context.server) {\n return optimizer.transformHTML(htmlIn);\n }\n },\n };\n}\n\nclass ScriptOptimizer {\n private emitted = new Map<string, string>();\n private transformState:\n | {\n htmlIn: string;\n htmlOut: string;\n parsed: JSDOM;\n }\n | undefined;\n\n constructor(private rootDir: string) {}\n\n async optimizedScript(script: string): Promise<EmittedFile[]> {\n // loading these lazily here so they never load in non-production builds.\n // The node cache will ensures we only load them once.\n const [Terser, srcURL] = await Promise.all([import('terser'), import('source-map-url')]);\n\n let inCode = readFileSync(resolve(this.rootDir, script.slice(1)), 'utf8');\n let terserOpts: MinifyOptions = {};\n let fileRelativeSourceMapURL;\n let appRelativeSourceMapURL;\n if (srcURL.default.existsIn(inCode)) {\n fileRelativeSourceMapURL = srcURL.default.getFrom(inCode)!;\n appRelativeSourceMapURL = posix.join(dirname(script.slice(1)), fileRelativeSourceMapURL);\n let content;\n try {\n content = readJSONSync(resolve(this.rootDir, appRelativeSourceMapURL));\n } catch (err) {\n // the script refers to a sourcemap that doesn't exist, so we just leave\n // the map out.\n }\n if (content) {\n terserOpts.sourceMap = { content, url: fileRelativeSourceMapURL };\n }\n }\n let { code: outCode, map: outMap } = await Terser.default.minify(inCode, terserOpts);\n let finalFilename = await this.getFingerprintedFilename(script, outCode!);\n let emit: EmittedFile[] = [];\n emit.push({\n type: 'asset',\n fileName: finalFilename.slice(1),\n source: outCode!,\n });\n this.emitted.set(script, finalFilename);\n if (appRelativeSourceMapURL && outMap) {\n emit.push({\n type: 'asset',\n fileName: appRelativeSourceMapURL,\n source: JSON.stringify(outMap, null, 2),\n });\n }\n return emit;\n }\n\n async getFingerprintedFilename(filename: string, content: string): Promise<string> {\n let crypto = await import('crypto');\n let md5 = crypto.createHash('md5');\n md5.update(content);\n let hash = md5.digest('hex');\n let fileParts = filename.split('.');\n fileParts.splice(fileParts.length - 1, 0, hash);\n return fileParts.join('.');\n }\n\n transformHTML(htmlIn: string) {\n if (this.transformState?.htmlIn !== htmlIn) {\n let parsed = new JSDOM(htmlIn);\n let scriptTags = [...parsed.window.document.querySelectorAll('script')] as HTMLScriptElement[];\n for (let scriptTag of scriptTags) {\n if (scriptTag.type !== 'module') {\n let fingerprinted = this.emitted.get(scriptTag.src);\n if (fingerprinted) {\n scriptTag.src = fingerprinted;\n }\n }\n }\n let htmlOut = parsed.serialize();\n this.transformState = { htmlIn, parsed, htmlOut };\n }\n return this.transformState.htmlOut;\n }\n}\n"]}
@@ -2,18 +2,45 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.templateTag = templateTag;
4
4
  const pluginutils_1 = require("@rollup/pluginutils");
5
+ const fs_1 = require("fs");
5
6
  const content_tag_1 = require("content-tag");
6
- const gjsFilter = (0, pluginutils_1.createFilter)('**/*.{gjs,gts}?(\\?)*');
7
+ const gjsFilter = (0, pluginutils_1.createFilter)('**/*.gjs');
7
8
  function templateTag({ inline_source_map } = { inline_source_map: false }) {
8
9
  let preprocessor = new content_tag_1.Preprocessor();
10
+ function candidates(id) {
11
+ return [id + '.gjs'];
12
+ }
9
13
  return {
10
14
  name: 'embroider-template-tag',
11
15
  enforce: 'pre',
12
- transform(code, id) {
16
+ async resolveId(id, importer) {
17
+ let resolution = await this.resolve(id, importer, {
18
+ skipSelf: true,
19
+ });
20
+ if (resolution) {
21
+ return resolution;
22
+ }
23
+ for (let candidate of candidates(id)) {
24
+ resolution = await this.resolve(candidate, importer, {
25
+ skipSelf: true,
26
+ custom: {
27
+ embroider: {
28
+ enableCustomResolver: false,
29
+ },
30
+ },
31
+ });
32
+ if (resolution) {
33
+ return {
34
+ id: resolution.id,
35
+ };
36
+ }
37
+ }
38
+ },
39
+ load(id) {
13
40
  if (!gjsFilter(id)) {
14
41
  return null;
15
42
  }
16
- return preprocessor.process(code, {
43
+ return preprocessor.process((0, fs_1.readFileSync)(id, 'utf8'), {
17
44
  filename: id,
18
45
  inline_source_map: inline_source_map,
19
46
  });
@@ -1 +1 @@
1
- {"version":3,"file":"template-tag.js","sourceRoot":"","sources":["template-tag.ts"],"names":[],"mappings":";;AAMA,kCAiBC;AAvBD,qDAAmD;AAEnD,6CAA2C;AAE3C,MAAM,SAAS,GAAG,IAAA,0BAAY,EAAC,uBAAuB,CAAC,CAAC;AAExD,SAAgB,WAAW,CAAC,EAAE,iBAAiB,EAAE,GAAG,EAAE,iBAAiB,EAAE,KAAK,EAAE;IAC9E,IAAI,YAAY,GAAG,IAAI,0BAAY,EAAE,CAAC;IAEtC,OAAO;QACL,IAAI,EAAE,wBAAwB;QAC9B,OAAO,EAAE,KAAK;QAEd,SAAS,CAAC,IAAY,EAAE,EAAU;YAChC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,EAAE,CAAC;gBACnB,OAAO,IAAI,CAAC;YACd,CAAC;YACD,OAAO,YAAY,CAAC,OAAO,CAAC,IAAI,EAAE;gBAChC,QAAQ,EAAE,EAAE;gBACZ,iBAAiB,EAAE,iBAAiB;aACrC,CAAC,CAAC;QACL,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import { createFilter } from '@rollup/pluginutils';\nimport type { Plugin } from 'vite';\nimport { Preprocessor } from 'content-tag';\n\nconst gjsFilter = createFilter('**/*.{gjs,gts}?(\\\\?)*');\n\nexport function templateTag({ inline_source_map } = { inline_source_map: false }): Plugin {\n let preprocessor = new Preprocessor();\n\n return {\n name: 'embroider-template-tag',\n enforce: 'pre',\n\n transform(code: string, id: string) {\n if (!gjsFilter(id)) {\n return null;\n }\n return preprocessor.process(code, {\n filename: id,\n inline_source_map: inline_source_map,\n });\n },\n };\n}\n"]}
1
+ {"version":3,"file":"template-tag.js","sourceRoot":"","sources":["template-tag.ts"],"names":[],"mappings":";;AAOA,kCA6CC;AApDD,qDAAmD;AAEnD,2BAAkC;AAClC,6CAA2C;AAE3C,MAAM,SAAS,GAAG,IAAA,0BAAY,EAAC,UAAU,CAAC,CAAC;AAE3C,SAAgB,WAAW,CAAC,EAAE,iBAAiB,EAAE,GAAG,EAAE,iBAAiB,EAAE,KAAK,EAAE;IAC9E,IAAI,YAAY,GAAG,IAAI,0BAAY,EAAE,CAAC;IAEtC,SAAS,UAAU,CAAC,EAAU;QAC5B,OAAO,CAAC,EAAE,GAAG,MAAM,CAAC,CAAC;IACvB,CAAC;IAED,OAAO;QACL,IAAI,EAAE,wBAAwB;QAC9B,OAAO,EAAE,KAAK;QAEd,KAAK,CAAC,SAAS,CAAC,EAAU,EAAE,QAA4B;YACtD,IAAI,UAAU,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,EAAE,EAAE,QAAQ,EAAE;gBAChD,QAAQ,EAAE,IAAI;aACf,CAAC,CAAC;YACH,IAAI,UAAU,EAAE,CAAC;gBACf,OAAO,UAAU,CAAC;YACpB,CAAC;YACD,KAAK,IAAI,SAAS,IAAI,UAAU,CAAC,EAAE,CAAC,EAAE,CAAC;gBACrC,UAAU,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,QAAQ,EAAE;oBACnD,QAAQ,EAAE,IAAI;oBACd,MAAM,EAAE;wBACN,SAAS,EAAE;4BACT,oBAAoB,EAAE,KAAK;yBAC5B;qBACF;iBACF,CAAC,CAAC;gBACH,IAAI,UAAU,EAAE,CAAC;oBACf,OAAO;wBACL,EAAE,EAAE,UAAU,CAAC,EAAE;qBAClB,CAAC;gBACJ,CAAC;YACH,CAAC;QACH,CAAC;QAED,IAAI,CAAC,EAAU;YACb,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,EAAE,CAAC;gBACnB,OAAO,IAAI,CAAC;YACd,CAAC;YACD,OAAO,YAAY,CAAC,OAAO,CAAC,IAAA,iBAAY,EAAC,EAAE,EAAE,MAAM,CAAC,EAAE;gBACpD,QAAQ,EAAE,EAAE;gBACZ,iBAAiB,EAAE,iBAAiB;aACrC,CAAC,CAAC;QACL,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import { createFilter } from '@rollup/pluginutils';\nimport type { Plugin } from 'vite';\nimport { readFileSync } from 'fs';\nimport { Preprocessor } from 'content-tag';\n\nconst gjsFilter = createFilter('**/*.gjs');\n\nexport function templateTag({ inline_source_map } = { inline_source_map: false }): Plugin {\n let preprocessor = new Preprocessor();\n\n function candidates(id: string) {\n return [id + '.gjs'];\n }\n\n return {\n name: 'embroider-template-tag',\n enforce: 'pre',\n\n async resolveId(id: string, importer: string | undefined) {\n let resolution = await this.resolve(id, importer, {\n skipSelf: true,\n });\n if (resolution) {\n return resolution;\n }\n for (let candidate of candidates(id)) {\n resolution = await this.resolve(candidate, importer, {\n skipSelf: true,\n custom: {\n embroider: {\n enableCustomResolver: false,\n },\n },\n });\n if (resolution) {\n return {\n id: resolution.id,\n };\n }\n }\n },\n\n load(id: string) {\n if (!gjsFilter(id)) {\n return null;\n }\n return preprocessor.process(readFileSync(id, 'utf8'), {\n filename: id,\n inline_source_map: inline_source_map,\n });\n },\n };\n}\n"]}
package/src/assets.d.ts DELETED
@@ -1,2 +0,0 @@
1
- import type { Plugin } from 'vite';
2
- export declare function assets(): Plugin;
package/src/assets.js DELETED
@@ -1,114 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.assets = assets;
30
- const core_1 = require("@embroider/core");
31
- const process = __importStar(require("process"));
32
- const path_1 = require("path");
33
- const fs_extra_1 = require("fs-extra");
34
- const send_1 = __importDefault(require("send"));
35
- function findPublicAsset(relativePath, resolver) {
36
- var _a;
37
- const packageCache = resolver.packageCache;
38
- let pkg = packageCache.ownerOfFile(relativePath);
39
- for (const engine of resolver.options.engines) {
40
- for (const addon of engine.activeAddons) {
41
- pkg = packageCache.ownerOfFile(addon.root);
42
- if (pkg && pkg.meta && pkg.isV2Addon() && pkg.meta['public-assets']) {
43
- const asset = (_a = Object.entries(pkg.meta['public-assets']).find(([_key, a]) => path_1.posix.resolve('/', a) === relativePath)) === null || _a === void 0 ? void 0 : _a[0];
44
- let local = asset ? (0, path_1.join)(addon.root, asset) : null;
45
- if (local && (0, fs_extra_1.existsSync)(local)) {
46
- return local;
47
- }
48
- }
49
- }
50
- }
51
- }
52
- function assets() {
53
- const cwd = process.cwd();
54
- const resolverLoader = new core_1.ResolverLoader(cwd);
55
- let mode = 'build';
56
- let publicDir = 'public';
57
- return {
58
- name: 'assets',
59
- enforce: 'post',
60
- configResolved(options) {
61
- mode = options.command;
62
- publicDir = options.publicDir;
63
- },
64
- configureServer(server) {
65
- return () => {
66
- server.middlewares.use((req, res, next) => {
67
- if (req.originalUrl && req.originalUrl.length > 1) {
68
- const assetUrl = findPublicAsset(req.originalUrl.split('?')[0], resolverLoader.resolver);
69
- if (assetUrl) {
70
- return (0, send_1.default)(req, assetUrl).pipe(res);
71
- }
72
- }
73
- return next();
74
- });
75
- };
76
- },
77
- buildStart: {
78
- // we need to wait for the compatBuild plugin's buildStart hook to finish
79
- // so that the resolver config exists before we try to read it.
80
- sequential: true,
81
- order: 'post',
82
- async handler() {
83
- if (mode !== 'build')
84
- return;
85
- const engines = resolverLoader.resolver.options.engines;
86
- for (const engine of engines) {
87
- const packages = engine.activeAddons.map(a => resolverLoader.resolver.packageCache.ownerOfFile(a.root));
88
- packages.forEach(pkg => {
89
- if (!pkg || !pkg.isV2Addon())
90
- return;
91
- const assets = pkg.meta['public-assets'] || {};
92
- Object.entries(assets).forEach(([path, dest]) => {
93
- // do not override app public assets
94
- if ((0, fs_extra_1.existsSync)((0, path_1.join)(publicDir, dest))) {
95
- return;
96
- }
97
- const filePath = (0, path_1.join)(pkg.root, path);
98
- if (!(0, fs_extra_1.lstatSync)(filePath).isFile()) {
99
- console.log(`Invalid package definition, ${pkg.name} has defined a file "${path}" that is not a file`);
100
- return;
101
- }
102
- this.emitFile({
103
- type: 'asset',
104
- source: (0, fs_extra_1.readFileSync)(filePath),
105
- fileName: path_1.posix.resolve('/', dest).slice(1),
106
- });
107
- });
108
- });
109
- }
110
- },
111
- },
112
- };
113
- }
114
- //# sourceMappingURL=assets.js.map
package/src/assets.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"assets.js","sourceRoot":"","sources":["assets.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BA,wBA6DC;AAzFD,0CAAiD;AAEjD,iDAAmC;AACnC,+BAAmC;AACnC,uCAA+D;AAC/D,gDAAwB;AAGxB,SAAS,eAAe,CAAC,YAAoB,EAAE,QAAkB;;IAC/D,MAAM,YAAY,GAAG,QAAQ,CAAC,YAAY,CAAC;IAC3C,IAAI,GAAG,GAAG,YAAY,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC;IAEjD,KAAK,MAAM,MAAM,IAAI,QAAQ,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;QAC9C,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,YAAY,EAAE,CAAC;YACxC,GAAG,GAAG,YAAY,CAAC,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YAC3C,IAAI,GAAG,IAAI,GAAG,CAAC,IAAI,IAAI,GAAG,CAAC,SAAS,EAAE,IAAI,GAAG,CAAC,IAAI,CAAC,eAAe,CAAC,EAAE,CAAC;gBACpE,MAAM,KAAK,GAAG,MAAA,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC,CAAC,IAAI,CAC1D,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,YAAK,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC,KAAK,YAAY,CACtD,0CAAG,CAAC,CAAC,CAAC;gBACP,IAAI,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC,IAAA,WAAI,EAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;gBACnD,IAAI,KAAK,IAAI,IAAA,qBAAU,EAAC,KA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C,CAAC,KAAK,CAAC,CAAC,CAAC;6BAC5C,CAAC,CAAC;wBACL,CAAC,CAAC,CAAC;oBACL,CAAC,CAAC,CAAC;gBACL,CAAC;YACH,CAAC;SACF;KACF,CAAC;AACJ,CAAC","sourcesContent":["import type { Resolver } from '@embroider/core';\nimport { ResolverLoader } from '@embroider/core';\nimport type { Plugin } from 'vite';\nimport * as process from 'process';\nimport { join, posix } from 'path';\nimport { existsSync, readFileSync, lstatSync } from 'fs-extra';\nimport send from 'send';\nimport type { Readable } from 'stream';\n\nfunction findPublicAsset(relativePath: string, resolver: Resolver) {\n const packageCache = resolver.packageCache;\n let pkg = packageCache.ownerOfFile(relativePath);\n\n for (const engine of resolver.options.engines) {\n for (const addon of engine.activeAddons) {\n pkg = packageCache.ownerOfFile(addon.root);\n if (pkg && pkg.meta && pkg.isV2Addon() && pkg.meta['public-assets']) {\n const asset = Object.entries(pkg.meta['public-assets']).find(\n ([_key, a]) => posix.resolve('/', a) === relativePath\n )?.[0];\n let local = asset ? join(addon.root, asset) : null;\n if (local && existsSync(local)) {\n return local;\n }\n }\n }\n }\n}\n\nexport function assets(): Plugin {\n const cwd = process.cwd();\n const resolverLoader = new ResolverLoader(cwd);\n let mode: 'build' | 'serve' = 'build';\n let publicDir = 'public';\n return {\n name: 'assets',\n enforce: 'post',\n configResolved(options) {\n mode = options.command;\n publicDir = options.publicDir;\n },\n configureServer(server) {\n return () => {\n server.middlewares.use((req, res, next) => {\n if (req.originalUrl && req.originalUrl.length > 1) {\n const assetUrl = findPublicAsset(req.originalUrl.split('?')[0], resolverLoader.resolver);\n if (assetUrl) {\n return send(req as Readable, assetUrl).pipe(res);\n }\n }\n return next();\n });\n };\n },\n buildStart: {\n // we need to wait for the compatBuild plugin's buildStart hook to finish\n // so that the resolver config exists before we try to read it.\n sequential: true,\n order: 'post',\n async handler() {\n if (mode !== 'build') return;\n const engines = resolverLoader.resolver.options.engines;\n for (const engine of engines) {\n const packages = engine.activeAddons.map(a => resolverLoader.resolver.packageCache.ownerOfFile(a.root));\n packages.forEach(pkg => {\n if (!pkg || !pkg.isV2Addon()) return;\n const assets = pkg.meta['public-assets'] || {};\n Object.entries(assets).forEach(([path, dest]) => {\n // do not override app public assets\n if (existsSync(join(publicDir, dest))) {\n return;\n }\n\n const filePath = join(pkg.root, path);\n if (!lstatSync(filePath).isFile()) {\n console.log(`Invalid package definition, ${pkg.name} has defined a file \"${path}\" that is not a file`);\n return;\n }\n\n this.emitFile({\n type: 'asset',\n source: readFileSync(filePath),\n fileName: posix.resolve('/', dest).slice(1),\n });\n });\n });\n }\n },\n },\n };\n}\n"]}
package/src/build.d.ts DELETED
@@ -1,3 +0,0 @@
1
- import type { Plugin } from 'vite';
2
- export declare function emberBuild(command: string, mode: string, resolvableExtensions: string[] | undefined): Promise<void>;
3
- export declare function compatPrebuild(): Plugin;
package/src/build.js DELETED
@@ -1,64 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.emberBuild = emberBuild;
4
- exports.compatPrebuild = compatPrebuild;
5
- const child_process_1 = require("child_process");
6
- function emberBuild(command, mode, resolvableExtensions) {
7
- let env = {
8
- ...process.env,
9
- EMBROIDER_PREBUILD: 'true',
10
- };
11
- if (resolvableExtensions) {
12
- env['EMBROIDER_RESOLVABLE_EXTENSIONS'] = resolvableExtensions === null || resolvableExtensions === void 0 ? void 0 : resolvableExtensions.join(',');
13
- }
14
- if (command === 'build') {
15
- return new Promise((resolve, reject) => {
16
- const child = (0, child_process_1.fork)('./node_modules/ember-cli/bin/ember', ['build', '--environment', mode], { env });
17
- child.on('exit', code => (code === 0 ? resolve() : reject()));
18
- });
19
- }
20
- return new Promise((resolve, reject) => {
21
- const child = (0, child_process_1.fork)('./node_modules/ember-cli/bin/ember', ['build', '--watch', '--environment', mode], {
22
- silent: true,
23
- env,
24
- });
25
- child.on('exit', code => (code === 0 ? resolve() : reject(new Error('ember build --watch failed'))));
26
- child.on('spawn', () => {
27
- var _a;
28
- (_a = child.stderr) === null || _a === void 0 ? void 0 : _a.on('data', data => {
29
- console.error(data.toString());
30
- });
31
- child.stdout.on('data', data => {
32
- console.log(data.toString());
33
- if (data.toString().includes('Build successful')) {
34
- resolve();
35
- }
36
- });
37
- });
38
- });
39
- }
40
- function compatPrebuild() {
41
- let viteCommand;
42
- let viteMode;
43
- let resolvableExtensions;
44
- return {
45
- name: 'embroider-builder',
46
- enforce: 'pre',
47
- config(config, { mode, command }) {
48
- var _a;
49
- viteCommand = command;
50
- viteMode = mode;
51
- resolvableExtensions = (_a = config.resolve) === null || _a === void 0 ? void 0 : _a.extensions;
52
- },
53
- async buildStart() {
54
- if (!viteCommand) {
55
- throw new Error(`bug: embroider compatPrebuild did not detect Vite's command`);
56
- }
57
- if (!viteMode) {
58
- throw new Error(`bug: embroider compatPrebuild did not detect Vite's mode`);
59
- }
60
- await emberBuild(viteCommand, viteMode, resolvableExtensions);
61
- },
62
- };
63
- }
64
- //# sourceMappingURL=build.js.map
package/src/build.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"build.js","sourceRoot":"","sources":["build.ts"],"names":[],"mappings":";;AAGA,gCAkCC;AAED,wCAuBC;AA9DD,iDAAqC;AAGrC,SAAgB,UAAU,CAAC,OAAe,EAAE,IAAY,EAAE,oBAA0C;IAClG,IAAI,GAAG,GAA2B;QAChC,GAAG,OAAO,CAAC,GAAG;QACd,kBAAkB,EAAE,MAAM;KAC3B,CAAC;IAEF,IAAI,oBAAoB,EAAE,CAAC;QACzB,GAAG,CAAC,iCAAiC,CAAC,GAAG,oBAAoB,aAApB,oBAAoB,uBAApB,oBAAoB,CAAE,IAAI,CAAC,GAAG,CAAC,CAAC;IAC3E,CAAC;IAED,IAAI,OAAO,KAAK,OAAO,EAAE,CAAC;QACxB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACrC,MAAM,KAAK,GAAG,IAAA,oBAAI,EAAC,oCAAoC,EAAE,CAAC,OAAO,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,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC;AAED,SAAgB,cAAc;IAC5B,IAAI,WAA+B,CAAC;IACpC,IAAI,QAA4B,CAAC;IACjC,IAAI,oBAA0C,CAAC;IAE/C,OAAO;QACL,IAAI,EAAE,mBAAmB;QACzB,OAAO,EAAE,KAAK;QACd,MAAM,CAAC,MAAM,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE;;YAC9B,WAAW,GAAG,OAAO,CAAC;YACtB,QAAQ,GAAG,IAAI,CAAC;YAChB,oBAAoB,GAAG,MAAA,MAAM,CAAC,OAAO,0CAAE,UAAU,CAAC;QACpD,CAAC;QACD,KAAK,CAAC,UAAU;YACd,IAAI,CAAC,WAAW,EAAE,CAAC;gBACjB,MAAM,IAAI,KAAK,CAAC,6DAA6D,CAAC,CAAC;YACjF,CAAC;YACD,IAAI,CAAC,QAAQ,EAAE,CAAC;gBACd,MAAM,IAAI,KAAK,CAAC,0DAA0D,CAAC,CAAC;YAC9E,CAAC;YACD,MAAM,UAAU,CAAC,WAAW,EAAE,QAAQ,EAAE,oBAAoB,CAAC,CAAC;QAChE,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import { fork } from 'child_process';\nimport type { Plugin } from 'vite';\n\nexport function emberBuild(command: string, mode: string, resolvableExtensions: string[] | undefined): Promise<void> {\n let env: Record<string, string> = {\n ...process.env,\n EMBROIDER_PREBUILD: 'true',\n };\n\n if (resolvableExtensions) {\n env['EMBROIDER_RESOLVABLE_EXTENSIONS'] = resolvableExtensions?.join(',');\n }\n\n if (command === 'build') {\n return new Promise((resolve, reject) => {\n const child = fork('./node_modules/ember-cli/bin/ember', ['build', '--environment', mode], { env });\n child.on('exit', code => (code === 0 ? resolve() : reject()));\n });\n }\n return new Promise((resolve, reject) => {\n const child = fork('./node_modules/ember-cli/bin/ember', ['build', '--watch', '--environment', mode], {\n silent: true,\n env,\n });\n child.on('exit', code => (code === 0 ? resolve() : reject(new Error('ember build --watch failed'))));\n child.on('spawn', () => {\n child.stderr?.on('data', data => {\n console.error(data.toString());\n });\n child.stdout!.on('data', data => {\n console.log(data.toString());\n if (data.toString().includes('Build successful')) {\n resolve();\n }\n });\n });\n });\n}\n\nexport function compatPrebuild(): Plugin {\n let viteCommand: string | undefined;\n let viteMode: string | undefined;\n let resolvableExtensions: string[] | undefined;\n\n return {\n name: 'embroider-builder',\n enforce: 'pre',\n config(config, { mode, command }) {\n viteCommand = command;\n viteMode = mode;\n resolvableExtensions = config.resolve?.extensions;\n },\n async buildStart() {\n if (!viteCommand) {\n throw new Error(`bug: embroider compatPrebuild did not detect Vite's command`);\n }\n if (!viteMode) {\n throw new Error(`bug: embroider compatPrebuild did not detect Vite's mode`);\n }\n await emberBuild(viteCommand, viteMode, resolvableExtensions);\n },\n };\n}\n"]}
@@ -1,2 +0,0 @@
1
- import type { Plugin } from 'vite';
2
- export declare function contentFor(): Plugin;
@@ -1,20 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.contentFor = contentFor;
4
- const fs_extra_1 = require("fs-extra");
5
- const path_1 = require("path");
6
- const core_1 = require("@embroider/core");
7
- function contentFor() {
8
- return {
9
- name: 'embroider-content-for',
10
- transformIndexHtml(html, { path }) {
11
- let config = (0, fs_extra_1.readJSONSync)((0, path_1.join)((0, core_1.locateEmbroiderWorkingDir)(process.cwd()), 'content-for.json'));
12
- let contentsForConfig = config[path];
13
- for (const [contentType, htmlContent] of Object.entries(contentsForConfig)) {
14
- html = html.replace(`{{content-for "${contentType}"}}`, `${htmlContent}`);
15
- }
16
- return html;
17
- },
18
- };
19
- }
20
- //# sourceMappingURL=content-for.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"content-for.js","sourceRoot":"","sources":["content-for.ts"],"names":[],"mappings":";;AAKA,gCAaC;AAjBD,uCAAwC;AACxC,+BAA4B;AAC5B,0CAA4D;AAE5D,SAAgB,UAAU;IACxB,OAAO;QACL,IAAI,EAAE,uBAAuB;QAE7B,kBAAkB,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE;YAC/B,IAAI,MAAM,GAAQ,IAAA,uBAAY,EAAC,IAAA,WAAI,EAAC,IAAA,gCAAyB,EAAC,OAAO,CAAC,GAAG,EAAE,CAAC,EAAE,kBAAkB,CAAC,CAAC,CAAC;YACnG,IAAI,iBAAiB,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;YACrC,KAAK,MAAM,CAAC,WAAW,EAAE,WAAW,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,iBAAiB,CAAC,EAAE,CAAC;gBAC3E,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,kBAAkB,WAAW,KAAK,EAAE,GAAG,WAAW,EAAE,CAAC,CAAC;YAC5E,CAAC;YACD,OAAO,IAAI,CAAC;QACd,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import type { Plugin } from 'vite';\nimport { readJSONSync } from 'fs-extra';\nimport { join } from 'path';\nimport { locateEmbroiderWorkingDir } from '@embroider/core';\n\nexport function contentFor(): Plugin {\n return {\n name: 'embroider-content-for',\n\n transformIndexHtml(html, { path }) {\n let config: any = readJSONSync(join(locateEmbroiderWorkingDir(process.cwd()), 'content-for.json'));\n let contentsForConfig = config[path];\n for (const [contentType, htmlContent] of Object.entries(contentsForConfig)) {\n html = html.replace(`{{content-for \"${contentType}\"}}`, `${htmlContent}`);\n }\n return html;\n },\n };\n}\n"]}
@@ -1,31 +0,0 @@
1
- import { type ModuleRequest } from '@embroider/core';
2
- import type { ImportKind, OnResolveResult, PluginBuild } from 'esbuild';
3
- import type { PackageCache as _PackageCache, Resolution } from '@embroider/core';
4
- type PublicAPI<T> = {
5
- [K in keyof T]: T[K];
6
- };
7
- type PackageCache = PublicAPI<_PackageCache>;
8
- export declare class EsBuildModuleRequest implements ModuleRequest {
9
- private packageCache;
10
- private phase;
11
- private context;
12
- private kind;
13
- readonly specifier: string;
14
- readonly fromFile: string;
15
- readonly meta: Record<string, any> | undefined;
16
- readonly isVirtual: boolean;
17
- readonly isNotFound: boolean;
18
- readonly resolvedTo: Resolution<OnResolveResult, OnResolveResult> | undefined;
19
- static from(packageCache: PackageCache, phase: 'bundling' | 'scanning', context: PluginBuild, kind: ImportKind, source: string, importer: string | undefined, pluginData: Record<string, any> | undefined): EsBuildModuleRequest | undefined;
20
- private constructor();
21
- get debugType(): string;
22
- alias(newSpecifier: string): this;
23
- rehome(newFromFile: string): this;
24
- virtualize(filename: string): this;
25
- withMeta(meta: Record<string, any> | undefined): this;
26
- notFound(): this;
27
- resolveTo(resolution: Resolution<OnResolveResult, OnResolveResult>): this;
28
- defaultResolve(): Promise<Resolution<OnResolveResult, OnResolveResult>>;
29
- }
30
- export declare function writeStatus(id: string, status: 'found' | 'not_found'): void;
31
- export {};
@@ -1,166 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.EsBuildModuleRequest = void 0;
4
- exports.writeStatus = writeStatus;
5
- const core_1 = require("@embroider/core");
6
- const path_1 = require("path");
7
- const reverse_exports_1 = require("@embroider/reverse-exports");
8
- class EsBuildModuleRequest {
9
- static from(packageCache, phase, context, kind, source, importer, pluginData) {
10
- var _a, _b, _c;
11
- if (!((_b = (_a = pluginData === null || pluginData === void 0 ? void 0 : pluginData.embroider) === null || _a === void 0 ? void 0 : _a.enableCustomResolver) !== null && _b !== void 0 ? _b : true)) {
12
- return;
13
- }
14
- if (source && importer && source[0] !== '\0' && !source.startsWith('virtual-module:')) {
15
- let fromFile = (0, core_1.cleanUrl)(importer);
16
- return new EsBuildModuleRequest(packageCache, phase, context, kind, source, fromFile, (_c = pluginData === null || pluginData === void 0 ? void 0 : pluginData.embroider) === null || _c === void 0 ? void 0 : _c.meta, false, false, undefined);
17
- }
18
- }
19
- constructor(packageCache, phase, context, kind, specifier, fromFile, meta, isVirtual, isNotFound, resolvedTo) {
20
- this.packageCache = packageCache;
21
- this.phase = phase;
22
- this.context = context;
23
- this.kind = kind;
24
- this.specifier = specifier;
25
- this.fromFile = fromFile;
26
- this.meta = meta;
27
- this.isVirtual = isVirtual;
28
- this.isNotFound = isNotFound;
29
- this.resolvedTo = resolvedTo;
30
- }
31
- get debugType() {
32
- return 'esbuild';
33
- }
34
- alias(newSpecifier) {
35
- return new EsBuildModuleRequest(this.packageCache, this.phase, this.context, this.kind, newSpecifier, this.fromFile, this.meta, this.isVirtual, false, undefined);
36
- }
37
- rehome(newFromFile) {
38
- if (this.fromFile === newFromFile) {
39
- return this;
40
- }
41
- else {
42
- return new EsBuildModuleRequest(this.packageCache, this.phase, this.context, this.kind, this.specifier, newFromFile, this.meta, this.isVirtual, false, undefined);
43
- }
44
- }
45
- virtualize(filename) {
46
- return new EsBuildModuleRequest(this.packageCache, this.phase, this.context, this.kind, filename, this.fromFile, this.meta, true, false, undefined);
47
- }
48
- withMeta(meta) {
49
- return new EsBuildModuleRequest(this.packageCache, this.phase, this.context, this.kind, this.specifier, this.fromFile, meta, this.isVirtual, this.isNotFound, this.resolvedTo);
50
- }
51
- notFound() {
52
- return new EsBuildModuleRequest(this.packageCache, this.phase, this.context, this.kind, this.specifier, this.fromFile, this.meta, this.isVirtual, true, undefined);
53
- }
54
- resolveTo(resolution) {
55
- return new EsBuildModuleRequest(this.packageCache, this.phase, this.context, this.kind, this.specifier, this.fromFile, this.meta, this.isVirtual, this.isNotFound, resolution);
56
- }
57
- async defaultResolve() {
58
- const request = this;
59
- if (request.isVirtual) {
60
- return {
61
- type: 'found',
62
- filename: request.specifier,
63
- result: { path: request.specifier, namespace: 'embroider-virtual' },
64
- isVirtual: this.isVirtual,
65
- };
66
- }
67
- if (request.isNotFound) {
68
- // todo: make sure this looks correct to users
69
- return {
70
- type: 'not_found',
71
- err: {
72
- errors: [{ text: `module not found ${request.specifier}` }],
73
- },
74
- };
75
- }
76
- requestStatus(request.specifier);
77
- let result = await this.context.resolve(request.specifier, {
78
- importer: request.fromFile,
79
- resolveDir: (0, path_1.dirname)(request.fromFile),
80
- kind: this.kind,
81
- pluginData: {
82
- embroider: {
83
- enableCustomResolver: false,
84
- meta: request.meta,
85
- },
86
- },
87
- });
88
- let status = readStatus(request.specifier);
89
- if (result.errors.length > 0 || status === 'not_found') {
90
- return { type: 'not_found', err: result };
91
- }
92
- else if (result.external) {
93
- return { type: 'ignored', result };
94
- }
95
- else {
96
- if (this.phase === 'bundling') {
97
- // we need to ensure that we don't traverse back into the app while
98
- // doing dependency pre-bundling. There are multiple ways an addon can
99
- // resolve things from the app, due to the existince of both app-js
100
- // (modules in addons that are logically part of the app's namespace)
101
- // and non-strict handlebars (which resolves
102
- // components/helpers/modifiers against the app's global pool).
103
- let pkg = this.packageCache.ownerOfFile(result.path);
104
- if ((pkg === null || pkg === void 0 ? void 0 : pkg.root) === this.packageCache.appRoot) {
105
- let externalizedName = request.specifier;
106
- if (!(0, core_1.packageName)(externalizedName)) {
107
- // the request was a relative path. This won't remain valid once
108
- // it has been bundled into vite/deps. But we know it targets the
109
- // app, so we can always convert it into a non-relative import
110
- // from the app's namespace
111
- //
112
- // IMPORTANT: whenever an addon resolves a relative path to the
113
- // app, it does so because our code in the core resolver has
114
- // rewritten the request to be relative to the app's root. So here
115
- // we will only ever encounter relative paths that are already
116
- // relative to the app's root directory.
117
- externalizedName = (0, reverse_exports_1.externalName)(pkg.packageJSON, externalizedName) || externalizedName;
118
- }
119
- return {
120
- type: 'ignored',
121
- result: {
122
- path: externalizedName,
123
- external: true,
124
- },
125
- };
126
- }
127
- }
128
- return { type: 'found', filename: result.path, result, isVirtual: this.isVirtual };
129
- }
130
- }
131
- }
132
- exports.EsBuildModuleRequest = EsBuildModuleRequest;
133
- /*
134
- This is an unfortunate necessity. During depscan, vite deliberately hides
135
- information from esbuild. Specifically, it treats "not found" and "this is an
136
- external dependency" as both "external: true". But we really care about the
137
- difference, since we have fallback behaviors for the "not found" case. Using
138
- this global state, our rollup resolver plugin can observe what vite is
139
- actually doing and communicate that knowledge outward to our esbuild resolver
140
- plugin.
141
- */
142
- function sharedGlobalState() {
143
- let channel = globalThis.__embroider_vite_resolver_channel__;
144
- if (!channel) {
145
- channel = new Map();
146
- globalThis.__embroider_vite_resolver_channel__ = channel;
147
- }
148
- return channel;
149
- }
150
- function requestStatus(id) {
151
- sharedGlobalState().set(id, 'pending');
152
- }
153
- function writeStatus(id, status) {
154
- let channel = sharedGlobalState();
155
- if (channel.get(id) === 'pending') {
156
- channel.set(id, status);
157
- }
158
- }
159
- function readStatus(id) {
160
- var _a;
161
- let channel = sharedGlobalState();
162
- let result = (_a = channel.get(id)) !== null && _a !== void 0 ? _a : 'pending';
163
- channel.delete(id);
164
- return result;
165
- }
166
- //# sourceMappingURL=esbuild-request.js.map