@embroider/core 3.5.0 → 3.5.1-unstable.1c0f616

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.
Files changed (68) hide show
  1. package/package.json +22 -11
  2. package/src/app-files.d.ts +3 -5
  3. package/src/app-files.js +25 -8
  4. package/src/app-files.js.map +1 -1
  5. package/src/index.d.ts +5 -5
  6. package/src/index.js +3 -4
  7. package/src/index.js.map +1 -1
  8. package/src/measure-concat.js +1 -2
  9. package/src/measure-concat.js.map +1 -1
  10. package/src/messages.js.map +1 -1
  11. package/src/module-request.d.ts +44 -0
  12. package/src/module-request.js +100 -0
  13. package/src/module-request.js.map +1 -0
  14. package/src/module-resolver-options.d.ts +42 -0
  15. package/src/module-resolver-options.js +164 -0
  16. package/src/module-resolver-options.js.map +1 -0
  17. package/src/module-resolver.d.ts +24 -61
  18. package/src/module-resolver.js +469 -322
  19. package/src/module-resolver.js.map +1 -1
  20. package/src/node-resolve.d.ts +35 -0
  21. package/src/node-resolve.js +130 -0
  22. package/src/node-resolve.js.map +1 -0
  23. package/src/options.d.ts +0 -7
  24. package/src/options.js +0 -1
  25. package/src/options.js.map +1 -1
  26. package/src/packager.d.ts +0 -8
  27. package/src/packager.js +0 -9
  28. package/src/packager.js.map +1 -1
  29. package/src/resolver-loader.js +8 -1
  30. package/src/resolver-loader.js.map +1 -1
  31. package/src/virtual-content.d.ts +32 -12
  32. package/src/virtual-content.js +83 -184
  33. package/src/virtual-content.js.map +1 -1
  34. package/src/virtual-entrypoint.d.ts +21 -0
  35. package/src/virtual-entrypoint.js +273 -0
  36. package/src/virtual-entrypoint.js.map +1 -0
  37. package/src/virtual-route-entrypoint.d.ts +10 -0
  38. package/src/virtual-route-entrypoint.js +62 -0
  39. package/src/virtual-route-entrypoint.js.map +1 -0
  40. package/src/virtual-test-support-styles.d.ts +7 -0
  41. package/src/virtual-test-support-styles.js +61 -0
  42. package/src/virtual-test-support-styles.js.map +1 -0
  43. package/src/virtual-test-support.d.ts +7 -0
  44. package/src/virtual-test-support.js +65 -0
  45. package/src/virtual-test-support.js.map +1 -0
  46. package/src/virtual-vendor-styles.d.ts +8 -0
  47. package/src/virtual-vendor-styles.js +83 -0
  48. package/src/virtual-vendor-styles.js.map +1 -0
  49. package/src/virtual-vendor.d.ts +7 -0
  50. package/src/virtual-vendor.js +53 -0
  51. package/src/virtual-vendor.js.map +1 -0
  52. package/types/virtual/index.d.ts +9 -0
  53. package/types/virtual/index.js +3 -0
  54. package/src/asset.d.ts +0 -32
  55. package/src/asset.js +0 -3
  56. package/src/asset.js.map +0 -1
  57. package/src/ember-html.d.ts +0 -43
  58. package/src/ember-html.js +0 -110
  59. package/src/ember-html.js.map +0 -1
  60. package/src/portable-babel-config.d.ts +0 -11
  61. package/src/portable-babel-config.js +0 -132
  62. package/src/portable-babel-config.js.map +0 -1
  63. package/src/portable-babel-launcher.d.ts +0 -6
  64. package/src/portable-babel-launcher.js +0 -75
  65. package/src/portable-babel-launcher.js.map +0 -1
  66. package/src/to-broccoli-plugin.d.ts +0 -8
  67. package/src/to-broccoli-plugin.js +0 -30
  68. package/src/to-broccoli-plugin.js.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node-resolve.js","sourceRoot":"","sources":["node-resolve.ts"],"names":[],"mappings":";;;;;;AAkIA,kCAqBC;AAvJD,uDAAyE;AACzE,+BAAoD;AACpD,kEAA+D;AAC/D,gEAAuC;AAEvC,8DAA8D;AAC9D,qDAAkH;AAGlH,MAAa,kBAAkB;IAe7B,YAA4B,QAAkB,EAAU,UAAoB;QAAhD,aAAQ,GAAR,QAAQ,CAAU;QAAU,eAAU,GAAV,UAAU,CAAU;IAAG,CAAC;IAEhF,IAAI,SAAS;QACX,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,gBAAgB,CAAC,OAAyD;QACxE,IAAI,GAAG,GAAG,IAAI,KAAK,CAAC,oBAAoB,OAAO,CAAC,SAAS,EAAE,CAAC,CAAC;QAC5D,GA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C,QAAQ,CAAC,CAAC,UAAU,CAAC,SAAiB,EAAE,UAAoB;IAC1D,MAAM,SAAS,CAAC;IAEhB,KAAK,IAAI,GAAG,IAAI,UAAU,EAAE,CAAC;QAC3B,MAAM,GAAG,SAAS,GAAG,GAAG,EAAE,CAAC;IAC7B,CAAC;AACH,CAAC;AAUM,KAAK,UAAU,WAAW,CAC/B,QAAkB,EAClB,SAAiB,EACjB,QAAgB,EAChB,IAAsB;;IAEtB,IAAI,OAAO,GAAG,8BAAa,CAAC,MAAM,CAAC,kBAAkB,CAAC,MAAM,EAAE;QAC5D,QAAQ;QACR,QAAQ;QACR,SAAS;QACT,UAAU,EAAE,MAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,UAAU,mCAAI,iBAAiB;KAClD,CAAC,CAAC;IACH,IAAI,UAAU,GAAG,MAAM,QAAQ,CAAC,OAAO,CAAC,OAAQ,CAAC,CAAC;IAClD,QAAQ,UAAU,CAAC,IAAI,EAAE,CAAC;QACxB,KAAK,WAAW;YACd,OAAO,UAAU,CAAC;QACpB,KAAK,OAAO;YACV,OAAO,UAAU,CAAC,MAAM,CAAC;QAC3B;YACE,MAAM,IAAA,sBAAW,EAAC,UAAU,CAAC,CAAC;IAClC,CAAC;AACH,CAAC","sourcesContent":["import { virtualContent, type VirtualResponse } from './virtual-content';\nimport { dirname, resolve, isAbsolute } from 'path';\nimport { explicitRelative } from '@embroider/shared-internals';\nimport assertNever from 'assert-never';\n\n// these would be circular, but they're type-only so it's fine\nimport { ModuleRequest, type RequestAdapter, type RequestAdapterCreate, type Resolution } from './module-request';\nimport type { Resolver } from './module-resolver';\n\nexport class NodeRequestAdapter implements RequestAdapter<Resolution<NodeResolution, Error>> {\n static create: RequestAdapterCreate<\n { resolver: Resolver; specifier: string; fromFile: string; extensions: string[] },\n Resolution<NodeResolution, Error>\n > = ({ resolver, specifier, fromFile, extensions }) => {\n return {\n initialState: {\n specifier,\n fromFile,\n meta: undefined,\n },\n adapter: new NodeRequestAdapter(resolver, extensions),\n };\n };\n\n private constructor(private resolver: Resolver, private extensions: string[]) {}\n\n get debugType() {\n return 'node';\n }\n\n notFoundResponse(request: ModuleRequest<Resolution<NodeResolution, Error>>): Resolution<NodeResolution, Error> {\n let err = new Error(`module not found ${request.specifier}`);\n (err as any).code = 'MODULE_NOT_FOUND';\n return {\n type: 'not_found',\n err,\n };\n }\n\n virtualResponse(\n _request: ModuleRequest<Resolution<NodeResolution, Error>>,\n virtual: VirtualResponse\n ): Resolution<NodeResolution, Error> {\n return {\n type: 'found',\n filename: virtual.specifier,\n virtual,\n result: {\n type: 'virtual' as const,\n content: virtualContent(virtual, this.resolver).src,\n filename: virtual.specifier,\n },\n };\n }\n\n async resolve(request: ModuleRequest<Resolution<NodeResolution, Error>>): Promise<Resolution<NodeResolution, Error>> {\n // require.resolve does not like when we resolve from virtual paths.\n // That is, a request like \"../thing.js\" from\n // \"/a/real/path/VIRTUAL_SUBDIR/virtual.js\" has an unambiguous target of\n // \"/a/real/path/thing.js\", but require.resolve won't do that path\n // adjustment until after checking whether VIRTUAL_SUBDIR actually\n // exists.\n //\n // We can do the path adjustments before doing require.resolve.\n let { specifier } = request;\n let fromDir = dirname(request.fromFile);\n if (!isAbsolute(specifier) && specifier.startsWith('.')) {\n let targetPath = resolve(fromDir, specifier);\n let newFromDir = dirname(targetPath);\n if (fromDir !== newFromDir) {\n specifier = explicitRelative(newFromDir, targetPath);\n fromDir = newFromDir;\n }\n }\n\n let initialError;\n\n for (let candidate of candidates(specifier, this.extensions)) {\n let filename;\n try {\n filename = require.resolve(candidate, {\n paths: [fromDir],\n });\n } catch (err) {\n if (err.code !== 'MODULE_NOT_FOUND') {\n throw err;\n }\n\n if (!initialError) {\n initialError = err;\n }\n\n continue;\n }\n if (filename.endsWith('.hbs') && !candidate.endsWith('.hbs')) {\n // Evaluating the `handlebars` NPM package installs a Node extension\n // that puts `*.hbs` in the automatic search path. But we can't control\n // its priority, and it's really important to us that `.hbs` cannot\n // shadow other extensions with higher priority. For example, when both\n // `.ts` and `.hbs` exist, resolving is supposed to find the `.ts`.\n //\n // This covers the case where we found an hbs \"by accident\", when we\n // weren't actually expecting it.\n continue;\n }\n return { type: 'found', filename, result: { type: 'real' as 'real', filename }, virtual: false };\n }\n\n return { type: 'not_found', err: initialError };\n }\n}\n\nconst defaultExtensions = ['.hbs.js', '.hbs'];\n\nfunction* candidates(specifier: string, extensions: string[]) {\n yield specifier;\n\n for (let ext of extensions) {\n yield `${specifier}${ext}`;\n }\n}\n\ntype NodeResolution = { type: 'virtual'; filename: string; content: string } | { type: 'real'; filename: string };\n\ntype NodeResolutionError = { type: 'not_found'; err: Error };\n\nexport interface NodeResolveOpts {\n extensions?: string[];\n}\n\nexport async function nodeResolve(\n resolver: Resolver,\n specifier: string,\n fromFile: string,\n opts?: NodeResolveOpts\n): Promise<NodeResolution | NodeResolutionError> {\n let request = ModuleRequest.create(NodeRequestAdapter.create, {\n resolver,\n fromFile,\n specifier,\n extensions: opts?.extensions ?? defaultExtensions,\n });\n let resolution = await resolver.resolve(request!);\n switch (resolution.type) {\n case 'not_found':\n return resolution;\n case 'found':\n return resolution.result;\n default:\n throw assertNever(resolution);\n }\n}\n"]}
package/src/options.d.ts CHANGED
@@ -55,17 +55,10 @@ export default interface Options {
55
55
  staticInvokables?: boolean;
56
56
  splitAtRoutes?: (RegExp | string)[];
57
57
  staticAppPaths?: string[];
58
- skipBabel?: {
59
- package: string;
60
- semverRange?: string;
61
- }[];
62
58
  pluginHints?: {
63
59
  resolve: string[];
64
60
  useMethod?: string;
65
61
  }[];
66
- amdCompatibility?: false | 'cjs' | {
67
- es: [string, string[]][];
68
- };
69
62
  }
70
63
  export type CoreOptionsType = Required<Omit<Options, 'staticHelpers' | 'staticModifiers' | 'staticComponents' | 'staticInvokables'>> & Pick<Options, 'staticHelpers' | 'staticModifiers' | 'staticComponents' | 'staticInvokables'>;
71
64
  export declare function optionsWithDefaults(options?: Options): CoreOptionsType;
package/src/options.js CHANGED
@@ -5,7 +5,6 @@ function optionsWithDefaults(options) {
5
5
  let defaults = {
6
6
  splitAtRoutes: [],
7
7
  staticAppPaths: [],
8
- skipBabel: [],
9
8
  pluginHints: [],
10
9
  amdCompatibility: 'cjs',
11
10
  };
@@ -1 +1 @@
1
- {"version":3,"file":"options.js","sourceRoot":"","sources":["options.ts"],"names":[],"mappings":";;AA+JA,kDAYC;AAZD,SAAgB,mBAAmB,CAAC,OAAiB;IACnD,IAAI,QAAQ,GAAG;QACb,aAAa,EAAE,EAAE;QACjB,cAAc,EAAE,EAAE;QAClB,SAAS,EAAE,EAAE;QACb,WAAW,EAAE,EAAE;QACf,gBAAgB,EAAE,KAAc;KACjC,CAAC;IACF,IAAI,OAAO,EAAE,CAAC;QACZ,OAAO,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAC1C,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC","sourcesContent":["export default interface Options {\n /**\n * When true, we statically resolve all template helpers at build time. This\n * causes unused helpers to be left out of the build (\"tree shaking\" of\n * helpers).\n *\n * Defaults to false, which gives you greater compatibility with classic Ember\n * apps at the cost of bigger builds.\n *\n * Enabling this is a prerequisite for route splitting.\n *\n * @deprecated use staticInvokables instead\n */\n staticHelpers?: boolean;\n\n /**\n * When true, we statically resolve all modifiers at build time. This\n * causes unused modifiers to be left out of the build (\"tree shaking\" of\n * modifiers).\n *\n * Defaults to false, which gives you greater compatibility with classic Ember\n * apps at the cost of bigger builds.\n *\n * Enabling this is a prerequisite for route splitting.\n *\n * @deprecated use staticInvokables instead\n */\n staticModifiers?: boolean;\n\n /**\n * When true, we statically resolve all components at build time. This causes\n * unused components to be left out of the build (\"tree shaking\" of\n * components).\n *\n * Defaults to false, which gives you greater compatibility with classic Ember\n * apps at the cost of bigger builds.\n *\n * Enabling this is a prerequisite for route splitting.\n *\n * @deprecated use staticInvokables instead\n */\n staticComponents?: boolean;\n\n /**\n * When true, we statically resolve all components, modifiers, and helpers (collectively\n * knows as Invokables) at build time. This causes any unused Invokables to be left out\n * of the build if they are unused i.e. \"tree shaking\".\n *\n * Defaults to false which gives you greater compatibility with classic Ember apps at the\n * cost of bigger builds.\n *\n * This setting takes over from `staticHelpers`, `staticModifiers`, and `staticComponents`\n * because the Developer Experience was less than ideal if any of these settings did not\n * agree i.e. they all needed to be true or they all needed to be false.\n *\n * Enabling this is a prerequisite for route splitting.\n */\n staticInvokables?: boolean;\n\n // Enables per-route code splitting. Any route names that match these patterns\n // will be split out of the initial app payload. If you use this, you must\n // also add @embroider/router to your app. See [@embroider/router's\n // README](https://github.com/embroider-build/embroider/blob/main/packages/router/README.md)\n splitAtRoutes?: (RegExp | string)[];\n\n // Every file within your application's `app` directory is categorized as a\n // component, helper, modifier, route, route template, controller, or \"other\".\n //\n // This option lets you decide which \"other\" files should be loaded\n // statically. By default, all \"other\" files will be included in the build and\n // registered with Ember's runtime loader, because we can't know if somebody\n // is going to try to access them dynamically via Ember's resolver or AMD\n // runtime `require`.\n //\n // If you know that your files are only ever imported, you can list them here\n // and then they will only be included exactly where they're needed.\n //\n // Provide a list of directories or files relative to `/app`. For example\n //\n // staticAppPaths: ['lib']\n //\n // means that everything under your-project/app/lib will be loaded statically.\n //\n // This option has no effect on components (which are governed by\n // staticComponents), helpers (which are governed by staticHelpers), modifiers\n // (which are governed by staticModifiers) or the route-specific files (routes,\n // route templates, and controllers which are governed by splitAtRoutes).\n staticAppPaths?: string[];\n\n // By default, all modules that get imported into the app go through Babel, so\n // that all code will conform with your Babel targets. This option allows you\n // to turn Babel off for a particular package. You might need this to work\n // around a transpiler bug or you might use this as a build-performance\n // optimization if you've manually verified that a particular package doesn't\n // need transpilation to be safe in your target browsers.\n skipBabel?: { package: string; semverRange?: string }[];\n\n // This is a performance optimization that can help you avoid the \"Your build\n // is slower because some babel plugins are non-serializable\" penalty. If you\n // provide the locations of known non-serializable objects, we can discover\n // them and make them serializable.\n //\n // resolve is a list of paths to resolve, in a chain. This lets you resolve\n // your dependencies' dependencies, like: resolve: ['your-dependency',\n // 'inner-dependency/lib/transform']\n //\n // useMethod optionally lets you pick which property within the module to use.\n // If not provided, we use the module.exports itself.\n pluginHints?: { resolve: string[]; useMethod?: string }[];\n\n // Ember classically used a runtime AMD module loader.\n //\n // Embroider *can* locate the vast majority of modules statically, but when an\n // addon is doing something highly dynamic (like injecting AMD `define()`\n // statements directly into a <script>), we still may not be able to locate\n // them. So Embroider can emit a placeholder shim for the missing module that\n // attempts to locate it at runtime in the classic AMD loader.\n //\n // This shim can be generated as commonJS (cjs) or an ES module (es). The\n // default is cjs.\n //\n // CJS is useful when you're building in an environment that is tolerant of\n // mixed CJS and ES modules (like Webpack), because the set of exported names\n // from the module doesn't need to be known in advance. For this reason, CJS\n // shims are generated on-demand and are fully-automatic. This is the default\n // for maximum backward-compatibility.\n //\n // ES is useful when you're building in a strict ES module environment (like\n // Vite). It's fully spec-defined and doesn't suffer interoperability\n // complexities. The downside is, we can only emit a correct shim for a module\n // if you tell embroider what set of names it exports. Example:\n\n // emberExternals: {\n // es: [\n // // import { first, second } from \"my-library\";\n // ['my-library', ['first', 'second']],\n // // import Example from \"my-library/components/example\";\n // ['my-library/components/example', ['default']]\n // ];\n // }\n\n // It is not recommended to use `es` mode without also using\n // staticEmberSource, because without staticEmberSource ember itself needs\n // many external shims.\n //\n // false means we don't do any external shimming.\n amdCompatibility?:\n | false\n | 'cjs'\n | {\n es: [string, string[]][];\n };\n}\n\nexport type CoreOptionsType = Required<\n Omit<Options, 'staticHelpers' | 'staticModifiers' | 'staticComponents' | 'staticInvokables'>\n> &\n Pick<Options, 'staticHelpers' | 'staticModifiers' | 'staticComponents' | 'staticInvokables'>;\n\nexport function optionsWithDefaults(options?: Options): CoreOptionsType {\n let defaults = {\n splitAtRoutes: [],\n staticAppPaths: [],\n skipBabel: [],\n pluginHints: [],\n amdCompatibility: 'cjs' as const,\n };\n if (options) {\n return Object.assign(defaults, options);\n }\n return defaults;\n}\n"]}
1
+ {"version":3,"file":"options.js","sourceRoot":"","sources":["options.ts"],"names":[],"mappings":";;AA4GA,kDAWC;AAXD,SAAgB,mBAAmB,CAAC,OAAiB;IACnD,IAAI,QAAQ,GAAG;QACb,aAAa,EAAE,EAAE;QACjB,cAAc,EAAE,EAAE;QAClB,WAAW,EAAE,EAAE;QACf,gBAAgB,EAAE,KAAc;KACjC,CAAC;IACF,IAAI,OAAO,EAAE,CAAC;QACZ,OAAO,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAC1C,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC","sourcesContent":["export default interface Options {\n /**\n * When true, we statically resolve all template helpers at build time. This\n * causes unused helpers to be left out of the build (\"tree shaking\" of\n * helpers).\n *\n * Defaults to false, which gives you greater compatibility with classic Ember\n * apps at the cost of bigger builds.\n *\n * Enabling this is a prerequisite for route splitting.\n *\n * @deprecated use staticInvokables instead\n */\n staticHelpers?: boolean;\n\n /**\n * When true, we statically resolve all modifiers at build time. This\n * causes unused modifiers to be left out of the build (\"tree shaking\" of\n * modifiers).\n *\n * Defaults to false, which gives you greater compatibility with classic Ember\n * apps at the cost of bigger builds.\n *\n * Enabling this is a prerequisite for route splitting.\n *\n * @deprecated use staticInvokables instead\n */\n staticModifiers?: boolean;\n\n /**\n * When true, we statically resolve all components at build time. This causes\n * unused components to be left out of the build (\"tree shaking\" of\n * components).\n *\n * Defaults to false, which gives you greater compatibility with classic Ember\n * apps at the cost of bigger builds.\n *\n * Enabling this is a prerequisite for route splitting.\n *\n * @deprecated use staticInvokables instead\n */\n staticComponents?: boolean;\n\n /**\n * When true, we statically resolve all components, modifiers, and helpers (collectively\n * knows as Invokables) at build time. This causes any unused Invokables to be left out\n * of the build if they are unused i.e. \"tree shaking\".\n *\n * Defaults to false which gives you greater compatibility with classic Ember apps at the\n * cost of bigger builds.\n *\n * This setting takes over from `staticHelpers`, `staticModifiers`, and `staticComponents`\n * because the Developer Experience was less than ideal if any of these settings did not\n * agree i.e. they all needed to be true or they all needed to be false.\n *\n * Enabling this is a prerequisite for route splitting.\n */\n staticInvokables?: boolean;\n\n // Enables per-route code splitting. Any route names that match these patterns\n // will be split out of the initial app payload. If you use this, you must\n // also add @embroider/router to your app. See [@embroider/router's\n // README](https://github.com/embroider-build/embroider/blob/main/packages/router/README.md)\n splitAtRoutes?: (RegExp | string)[];\n\n // Every file within your application's `app` directory is categorized as a\n // component, helper, modifier, route, route template, controller, or \"other\".\n //\n // This option lets you decide which \"other\" files should be loaded\n // statically. By default, all \"other\" files will be included in the build and\n // registered with Ember's runtime loader, because we can't know if somebody\n // is going to try to access them dynamically via Ember's resolver or AMD\n // runtime `require`.\n //\n // If you know that your files are only ever imported, you can list them here\n // and then they will only be included exactly where they're needed.\n //\n // Provide a list of directories or files relative to `/app`. For example\n //\n // staticAppPaths: ['lib']\n //\n // means that everything under your-project/app/lib will be loaded statically.\n //\n // This option has no effect on components (which are governed by\n // staticComponents), helpers (which are governed by staticHelpers), modifiers\n // (which are governed by staticModifiers) or the route-specific files (routes,\n // route templates, and controllers which are governed by splitAtRoutes).\n staticAppPaths?: string[];\n\n // This is a performance optimization that can help you avoid the \"Your build\n // is slower because some babel plugins are non-serializable\" penalty. If you\n // provide the locations of known non-serializable objects, we can discover\n // them and make them serializable.\n //\n // resolve is a list of paths to resolve, in a chain. This lets you resolve\n // your dependencies' dependencies, like: resolve: ['your-dependency',\n // 'inner-dependency/lib/transform']\n //\n // useMethod optionally lets you pick which property within the module to use.\n // If not provided, we use the module.exports itself.\n pluginHints?: { resolve: string[]; useMethod?: string }[];\n}\n\nexport type CoreOptionsType = Required<\n Omit<Options, 'staticHelpers' | 'staticModifiers' | 'staticComponents' | 'staticInvokables'>\n> &\n Pick<Options, 'staticHelpers' | 'staticModifiers' | 'staticComponents' | 'staticInvokables'>;\n\nexport function optionsWithDefaults(options?: Options): CoreOptionsType {\n let defaults = {\n splitAtRoutes: [],\n staticAppPaths: [],\n pluginHints: [],\n amdCompatibility: 'cjs' as const,\n };\n if (options) {\n return Object.assign(defaults, options);\n }\n return defaults;\n}\n"]}
package/src/packager.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- import type { AppMeta } from '@embroider/shared-internals';
2
1
  export interface Variant {
3
2
  name: string;
4
3
  runtime: 'all' | 'browser' | 'fastboot';
@@ -12,13 +11,6 @@ export interface Packager {
12
11
  build(): Promise<void>;
13
12
  }
14
13
  export declare function applyVariantToBabelConfig(variant: Variant, babelConfig: any): any;
15
- /**
16
- * Get the app meta-data for a package
17
- */
18
- export declare function getAppMeta(pathToVanillaApp: string): {
19
- name: string;
20
- "ember-addon": AppMeta;
21
- };
22
14
  /**
23
15
  * Get the path to a cache directory in the recommended location
24
16
  *
package/src/packager.js CHANGED
@@ -1,10 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.applyVariantToBabelConfig = applyVariantToBabelConfig;
4
- exports.getAppMeta = getAppMeta;
5
4
  exports.getPackagerCacheDir = getPackagerCacheDir;
6
5
  const shared_internals_1 = require("@embroider/shared-internals");
7
- const fs_extra_1 = require("fs-extra");
8
6
  const lodash_1 = require("lodash");
9
7
  const path_1 = require("path");
10
8
  function applyVariantToBabelConfig(variant, babelConfig) {
@@ -25,13 +23,6 @@ function applyVariantToBabelConfig(variant, babelConfig) {
25
23
  }
26
24
  return babelConfig;
27
25
  }
28
- /**
29
- * Get the app meta-data for a package
30
- */
31
- function getAppMeta(pathToVanillaApp) {
32
- let pkg = JSON.parse((0, fs_extra_1.readFileSync)((0, path_1.join)(pathToVanillaApp, 'package.json'), 'utf8'));
33
- return pkg;
34
- }
35
26
  /**
36
27
  * Get the path to a cache directory in the recommended location
37
28
  *
@@ -1 +1 @@
1
- {"version":3,"file":"packager.js","sourceRoot":"","sources":["packager.ts"],"names":[],"mappings":";;AAwEA,8DAkBC;AAKD,gCAGC;AAOD,kDAEC;AA1GD,kEAAqD;AACrD,uCAAwC;AACxC,mCAAmC;AACnC,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AAC,IAAY;IAC9C,OAAO,IAAA,WAAI,EAAC,yBAAM,EAAE,WAAW,EAAE,IAAI,CAAC,CAAC;AACzC,CAAC","sourcesContent":["import type { AppMeta } from '@embroider/shared-internals';\nimport { tmpdir } from '@embroider/shared-internals';\nimport { readFileSync } from 'fs-extra';\nimport { cloneDeep } from 'lodash';\nimport { join } from 'path';\n\n// This is a collection of flags that convey what kind of build you want. They\n// are intended to be generic across Packagers, and it's up to Packager authors\n// to support each option (or not).\nexport interface Variant {\n // descriptive name that can be used by the packager to label which output\n // goes with which variant.\n name: string;\n\n // Which runtime should this build work in? Dev builds will typically be \"all\"\n // because we produce a single build that works in browser and fastboot. But\n // production builds can be divided into a browser-only variant and a\n // fastboot-only variant so that each can be separately optimized.\n //\n // Note that if you build *only* a fastboot variant, you're unlikely to end up\n // with any assets that can boot and run in the browser too, so the typical\n // thing to do is to have to two variants and for the packager to use the\n // assets from the browser build to generate browser-facing <script> tags in\n // the output of the fastboot build.\n runtime: 'all' | 'browser' | 'fastboot';\n\n // true if this build should be optimized for production, at the cost of\n // slower builds and/or worse debuggability\n optimizeForProduction: boolean;\n}\n\nexport interface PackagerConstructor<Options> {\n new (\n // where on disk the packager will find the app it's supposed to build. The\n // app and its addons will necessarily already be in v2 format, which is\n // what makes a Packager a cleanly separable stage that needs only a small\n // amount of ember-specific knowledge.\n inputPath: string,\n // where the packager should write the packaged app.\n outputPath: string,\n // list of active build variants. There is always at least one variant, but\n // there can be many.\n //\n // The main requirement for correctness is that the Packager is required to\n // apply each variant to the babel and template-compiler configs that it\n // finds in the app in order to build that variant.\n //\n // It is up to each Packager to decide how to combine the output from the\n // multiple variants. It might choose to just put them in separate\n // subdirectories of `outputPath`, or it might know how to combine them\n // correctly into one build that will run each variant under the appropriate\n // conditions.\n //\n // Not all packagers will support all arbitrary combinations of variants.\n variants: Variant[],\n // if possible, the packager should direct its console output through this\n // hook.\n consoleWrite: (message: string) => void,\n // A packager can have whatever custom options type it wants here. If the\n // packager is based on a third-party tool, this is where that tool's\n // configuration can go.\n options?: Options\n ): Packager;\n\n // a description for this packager that aids debugging & profiling\n annotation: string;\n}\n\nexport interface Packager {\n build(): Promise<void>;\n}\n\nexport function applyVariantToBabelConfig(variant: Variant, babelConfig: any) {\n if (variant.runtime === 'fastboot') {\n babelConfig = Object.assign({}, babelConfig);\n if (babelConfig.plugins) {\n babelConfig.plugins = babelConfig.plugins.slice();\n } else {\n babelConfig.plugins = [];\n }\n let macroPlugin = babelConfig.plugins.find(\n (p: any) => Array.isArray(p) && p[1] && p[1].embroiderMacrosConfigMarker\n );\n if (macroPlugin) {\n let modifiedMacroPlugin = cloneDeep(macroPlugin);\n modifiedMacroPlugin[1].globalConfig.fastboot = { isRunning: true };\n babelConfig.plugins.splice(babelConfig.plugins.indexOf(macroPlugin), 1, modifiedMacroPlugin);\n }\n }\n return babelConfig;\n}\n\n/**\n * Get the app meta-data for a package\n */\nexport function getAppMeta(pathToVanillaApp: string) {\n let pkg = JSON.parse(readFileSync(join(pathToVanillaApp, 'package.json'), 'utf8'));\n return pkg as unknown as { name: string; 'ember-addon': AppMeta };\n}\n\n/**\n * Get the path to a cache directory in the recommended location\n *\n * This ensures they have exactly the same lifetime as some of embroider's own caches.\n */\nexport function getPackagerCacheDir(name: string): string {\n return join(tmpdir, 'embroider', name);\n}\n"]}
1
+ {"version":3,"file":"packager.js","sourceRoot":"","sources":["packager.ts"],"names":[],"mappings":";;AAsEA,8DAkBC;AAOD,kDAEC;AAjGD,kEAAqD;AACrD,mCAAmC;AACnC,+BAA4B;AAoE5B,SAAgB,yBAAyB,CAAC,OAAgB,EAAE,WAAgB;IAC1E,IAAI,OAAO,CAAC,OAAO,KAAK,UAAU,EAAE,CAAC;QACnC,WAAW,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,WAAW,CAAC,CAAC;QAC7C,IAAI,WAAW,CAAC,OAAO,EAAE,CAAC;YACxB,WAAW,CAAC,OAAO,GAAG,WAAW,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;QACpD,CAAC;aAAM,CAAC;YACN,WAAW,CAAC,OAAO,GAAG,EAAE,CAAC;QAC3B,CAAC;QACD,IAAI,WAAW,GAAG,WAAW,CAAC,OAAO,CAAC,IAAI,CACxC,CAAC,CAAM,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,2BAA2B,CACzE,CAAC;QACF,IAAI,WAAW,EAAE,CAAC;YAChB,IAAI,mBAAmB,GAAG,IAAA,kBAAS,EAAC,WAAW,CAAC,CAAC;YACjD,mBAAmB,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,QAAQ,GAAG,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;YACnE,WAAW,CAAC,OAAO,CAAC,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE,CAAC,EAAE,mBAAmB,CAAC,CAAC;QAC/F,CAAC;IACH,CAAC;IACD,OAAO,WAAW,CAAC;AACrB,CAAC;AAED;;;;GAIG;AACH,SAAgB,mBAAmB,CAAC,IAAY;IAC9C,OAAO,IAAA,WAAI,EAAC,yBAAM,EAAE,WAAW,EAAE,IAAI,CAAC,CAAC;AACzC,CAAC","sourcesContent":["import { tmpdir } from '@embroider/shared-internals';\nimport { cloneDeep } from 'lodash';\nimport { join } from 'path';\n\n// This is a collection of flags that convey what kind of build you want. They\n// are intended to be generic across Packagers, and it's up to Packager authors\n// to support each option (or not).\nexport interface Variant {\n // descriptive name that can be used by the packager to label which output\n // goes with which variant.\n name: string;\n\n // Which runtime should this build work in? Dev builds will typically be \"all\"\n // because we produce a single build that works in browser and fastboot. But\n // production builds can be divided into a browser-only variant and a\n // fastboot-only variant so that each can be separately optimized.\n //\n // Note that if you build *only* a fastboot variant, you're unlikely to end up\n // with any assets that can boot and run in the browser too, so the typical\n // thing to do is to have to two variants and for the packager to use the\n // assets from the browser build to generate browser-facing <script> tags in\n // the output of the fastboot build.\n runtime: 'all' | 'browser' | 'fastboot';\n\n // true if this build should be optimized for production, at the cost of\n // slower builds and/or worse debuggability\n optimizeForProduction: boolean;\n}\n\nexport interface PackagerConstructor<Options> {\n new (\n // where on disk the packager will find the app it's supposed to build. The\n // app and its addons will necessarily already be in v2 format, which is\n // what makes a Packager a cleanly separable stage that needs only a small\n // amount of ember-specific knowledge.\n inputPath: string,\n // where the packager should write the packaged app.\n outputPath: string,\n // list of active build variants. There is always at least one variant, but\n // there can be many.\n //\n // The main requirement for correctness is that the Packager is required to\n // apply each variant to the babel and template-compiler configs that it\n // finds in the app in order to build that variant.\n //\n // It is up to each Packager to decide how to combine the output from the\n // multiple variants. It might choose to just put them in separate\n // subdirectories of `outputPath`, or it might know how to combine them\n // correctly into one build that will run each variant under the appropriate\n // conditions.\n //\n // Not all packagers will support all arbitrary combinations of variants.\n variants: Variant[],\n // if possible, the packager should direct its console output through this\n // hook.\n consoleWrite: (message: string) => void,\n // A packager can have whatever custom options type it wants here. If the\n // packager is based on a third-party tool, this is where that tool's\n // configuration can go.\n options?: Options\n ): Packager;\n\n // a description for this packager that aids debugging & profiling\n annotation: string;\n}\n\nexport interface Packager {\n build(): Promise<void>;\n}\n\nexport function applyVariantToBabelConfig(variant: Variant, babelConfig: any) {\n if (variant.runtime === 'fastboot') {\n babelConfig = Object.assign({}, babelConfig);\n if (babelConfig.plugins) {\n babelConfig.plugins = babelConfig.plugins.slice();\n } else {\n babelConfig.plugins = [];\n }\n let macroPlugin = babelConfig.plugins.find(\n (p: any) => Array.isArray(p) && p[1] && p[1].embroiderMacrosConfigMarker\n );\n if (macroPlugin) {\n let modifiedMacroPlugin = cloneDeep(macroPlugin);\n modifiedMacroPlugin[1].globalConfig.fastboot = { isRunning: true };\n babelConfig.plugins.splice(babelConfig.plugins.indexOf(macroPlugin), 1, modifiedMacroPlugin);\n }\n }\n return babelConfig;\n}\n\n/**\n * Get the path to a cache directory in the recommended location\n *\n * This ensures they have exactly the same lifetime as some of embroider's own caches.\n */\nexport function getPackagerCacheDir(name: string): string {\n return join(tmpdir, 'embroider', name);\n}\n"]}
@@ -14,6 +14,7 @@ var _ResolverLoader_resolver, _ResolverLoader_configFile, _ResolverLoader_watche
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.ResolverLoader = void 0;
16
16
  const fs_extra_1 = require("fs-extra");
17
+ const module_resolver_options_1 = require("./module-resolver-options");
17
18
  const module_resolver_1 = require("./module-resolver");
18
19
  const shared_internals_1 = require("@embroider/shared-internals");
19
20
  const path_1 = require("path");
@@ -37,7 +38,13 @@ class ResolverLoader {
37
38
  }
38
39
  get resolver() {
39
40
  if (!__classPrivateFieldGet(this, _ResolverLoader_resolver, "f")) {
40
- let config = (0, fs_extra_1.readJSONSync)((0, path_1.join)((0, shared_internals_1.locateEmbroiderWorkingDir)(this.appRoot), 'resolver.json'));
41
+ let config;
42
+ if ((0, fs_extra_1.existsSync)(__classPrivateFieldGet(this, _ResolverLoader_configFile, "f"))) {
43
+ config = (0, fs_extra_1.readJSONSync)(__classPrivateFieldGet(this, _ResolverLoader_configFile, "f"));
44
+ }
45
+ else {
46
+ config = (0, module_resolver_options_1.buildResolverOptions)({});
47
+ }
41
48
  __classPrivateFieldSet(this, _ResolverLoader_resolver, new module_resolver_1.Resolver(config), "f");
42
49
  }
43
50
  return __classPrivateFieldGet(this, _ResolverLoader_resolver, "f");
@@ -1 +1 @@
1
- {"version":3,"file":"resolver-loader.js","sourceRoot":"","sources":["resolver-loader.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,uCAAwC;AAExC,uDAA6C;AAC7C,kEAAwE;AACxE,+BAA4B;AAE5B,2BAAsC;AAEtC,MAAa,cAAc;IAKzB,YAAqB,OAAe,EAAE,KAAK,GAAG,KAAK;QAA9B,YAAO,GAAP,OAAO,CAAQ;QAJpC,2CAAgC;QAChC,6CAAoB;QACpB,0CAAgC;QAG9B,uBAAA,IAAI,8BAAe,IAAA,WAAI,EAAC,IAAA,4CAAyB,EAAC,IAAI,CAAC,OAAO,CAAC,EAAE,eAAe,CAAC,MAAA,CAAC;QAClF,IAAI,KAAK,EAAE,CAAC;YACV,uBAAA,IAAI,2BAAY,IAAA,UAAO,EAAC,uBAAA,IAAI,kCAAY,EAAE,EAAE,UAAU,EAAE,KAAK,EAAE,EAAE,GAAG,EAAE;gBACpE,uBAAA,IAAI,4BAAa,SAAS,MAAA,CAAC;YAC7B,CAAC,CAAC,MAAA,CAAC;QACL,CAAC;IACH,CAAC;IAED,KAAK;;QACH,MAAA,uBAAA,IAAI,+BAAS,0CAAE,KAAK,EAAE,CAAC;IACzB,CAAC;IAED,IAAI,QAAQ;QACV,IAAI,CAAC,uBAAA,IAAI,gCAAU,EAAE,CAAC;YACpB,IAAI,MAAM,GAAY,IAAA,uBAAY,EAAC,IAAA,WAAI,EAAC,IAAA,4CAAyB,EAAC,IAAI,CAAC,OAAO,CAAC,EAAE,eAAe,CAAC,CAAC,CAAC;YACnG,uBAAA,IAAI,4BAAa,IAAI,0BAAQ,CAAC,MAAM,CAAC,MAAA,CAAC;QACxC,CAAC;QACD,OAAO,uBAAA,IAAI,gCAAU,CAAC;IACxB,CAAC;CACF;AAzBD,wCAyBC","sourcesContent":["import { readJSONSync } from 'fs-extra';\nimport type { Options } from './module-resolver';\nimport { Resolver } from './module-resolver';\nimport { locateEmbroiderWorkingDir } from '@embroider/shared-internals';\nimport { join } from 'path';\nimport type { FSWatcher } from 'fs';\nimport { watch as fsWatch } from 'fs';\n\nexport class ResolverLoader {\n #resolver: Resolver | undefined;\n #configFile: string;\n #watcher: FSWatcher | undefined;\n\n constructor(readonly appRoot: string, watch = false) {\n this.#configFile = join(locateEmbroiderWorkingDir(this.appRoot), 'resolver.json');\n if (watch) {\n this.#watcher = fsWatch(this.#configFile, { persistent: false }, () => {\n this.#resolver = undefined;\n });\n }\n }\n\n close() {\n this.#watcher?.close();\n }\n\n get resolver(): Resolver {\n if (!this.#resolver) {\n let config: Options = readJSONSync(join(locateEmbroiderWorkingDir(this.appRoot), 'resolver.json'));\n this.#resolver = new Resolver(config);\n }\n return this.#resolver;\n }\n}\n"]}
1
+ {"version":3,"file":"resolver-loader.js","sourceRoot":"","sources":["resolver-loader.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,uCAAoD;AACpD,uEAA+E;AAC/E,uDAA6C;AAC7C,kEAAwE;AACxE,+BAA4B;AAE5B,2BAAsC;AAEtC,MAAa,cAAc;IAKzB,YAAqB,OAAe,EAAE,KAAK,GAAG,KAAK;QAA9B,YAAO,GAAP,OAAO,CAAQ;QAJpC,2CAAgC;QAChC,6CAAoB;QACpB,0CAAgC;QAG9B,uBAAA,IAAI,8BAAe,IAAA,WAAI,EAAC,IAAA,4CAAyB,EAAC,IAAI,CAAC,OAAO,CAAC,EAAE,eAAe,CAAC,MAAA,CAAC;QAClF,IAAI,KAAK,EAAE,CAAC;YACV,uBAAA,IAAI,2BAAY,IAAA,UAAO,EAAC,uBAAA,IAAI,kCAAY,EAAE,EAAE,UAAU,EAAE,KAAK,EAAE,EAAE,GAAG,EAAE;gBACpE,uBAAA,IAAI,4BAAa,SAAS,MAAA,CAAC;YAC7B,CAAC,CAAC,MAAA,CAAC;QACL,CAAC;IACH,CAAC;IAED,KAAK;;QACH,MAAA,uBAAA,IAAI,+BAAS,0CAAE,KAAK,EAAE,CAAC;IACzB,CAAC;IAED,IAAI,QAAQ;QACV,IAAI,CAAC,uBAAA,IAAI,gCAAU,EAAE,CAAC;YACpB,IAAI,MAAe,CAAC;YACpB,IAAI,IAAA,qBAAU,EAAC,uBAAA,IAAI,kCAAY,CAAC,EAAE,CAAC;gBACjC,MAAM,GAAG,IAAA,uBAAY,EAAC,uBAAA,IAAI,kCAAY,CAAC,CAAC;YAC1C,CAAC;iBAAM,CAAC;gBACN,MAAM,GAAG,IAAA,8CAAoB,EAAC,EAAE,CAAC,CAAC;YACpC,CAAC;YACD,uBAAA,IAAI,4BAAa,IAAI,0BAAQ,CAAC,MAAM,CAAC,MAAA,CAAC;QACxC,CAAC;QACD,OAAO,uBAAA,IAAI,gCAAU,CAAC;IACxB,CAAC;CACF;AA9BD,wCA8BC","sourcesContent":["import { existsSync, readJSONSync } from 'fs-extra';\nimport { buildResolverOptions, type Options } from './module-resolver-options';\nimport { Resolver } from './module-resolver';\nimport { locateEmbroiderWorkingDir } from '@embroider/shared-internals';\nimport { join } from 'path';\nimport type { FSWatcher } from 'fs';\nimport { watch as fsWatch } from 'fs';\n\nexport class ResolverLoader {\n #resolver: Resolver | undefined;\n #configFile: string;\n #watcher: FSWatcher | undefined;\n\n constructor(readonly appRoot: string, watch = false) {\n this.#configFile = join(locateEmbroiderWorkingDir(this.appRoot), 'resolver.json');\n if (watch) {\n this.#watcher = fsWatch(this.#configFile, { persistent: false }, () => {\n this.#resolver = undefined;\n });\n }\n }\n\n close() {\n this.#watcher?.close();\n }\n\n get resolver(): Resolver {\n if (!this.#resolver) {\n let config: Options;\n if (existsSync(this.#configFile)) {\n config = readJSONSync(this.#configFile);\n } else {\n config = buildResolverOptions({});\n }\n this.#resolver = new Resolver(config);\n }\n return this.#resolver;\n }\n}\n"]}
@@ -1,15 +1,35 @@
1
1
  import type { Resolver } from '.';
2
- export declare function virtualContent(filename: string, resolver: Resolver): string;
3
- export declare function virtualExternalESModule(specifier: string, exports: string[] | undefined): string;
4
- export declare function virtualExternalCJSModule(specifier: string): string;
5
- export declare function virtualPairComponent(hbsModule: string, jsModule: string | null): string;
6
- export declare function fastbootSwitch(specifier: string, fromFile: string, names: Set<string>): string;
7
- export declare function decodeFastbootSwitch(filename: string): {
8
- names: string[];
9
- hasDefaultExport: boolean;
10
- filename: string;
11
- } | undefined;
12
- export declare function decodeImplicitModules(filename: string): {
2
+ import { type TestSupportResponse } from './virtual-test-support';
3
+ import { type TestSupportStylesResponse } from './virtual-test-support-styles';
4
+ import { type VirtualVendorResponse } from './virtual-vendor';
5
+ import { type VirtualVendorStylesResponse } from './virtual-vendor-styles';
6
+ import { type EntrypointResponse } from './virtual-entrypoint';
7
+ import { type RouteEntrypointResponse } from './virtual-route-entrypoint';
8
+ export type VirtualResponse = {
9
+ specifier: string;
10
+ } & (FastbootSwitchResponse | ImplicitModulesResponse | EntrypointResponse | RouteEntrypointResponse | TestSupportResponse | TestSupportStylesResponse | VirtualVendorResponse | VirtualVendorStylesResponse | VirtualPairResponse | TemplateOnlyComponentResponse);
11
+ export interface VirtualContentResult {
12
+ src: string;
13
+ watches: string[];
14
+ }
15
+ export declare function virtualContent(response: VirtualResponse, resolver: Resolver): VirtualContentResult;
16
+ export interface VirtualPairResponse {
17
+ type: 'component-pair';
18
+ specifier: string;
19
+ hbsModule: string;
20
+ jsModule: string | null;
21
+ debugName: string;
22
+ }
23
+ interface FastbootSwitchResponse {
24
+ type: 'fastboot-switch';
25
+ names: Set<string>;
26
+ }
27
+ export interface ImplicitModulesResponse {
13
28
  type: 'implicit-modules' | 'implicit-test-modules';
14
29
  fromFile: string;
15
- } | undefined;
30
+ }
31
+ export interface TemplateOnlyComponentResponse {
32
+ type: 'template-only-component-js';
33
+ specifier: string;
34
+ }
35
+ export {};
@@ -1,71 +1,59 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.virtualContent = virtualContent;
4
- exports.virtualExternalESModule = virtualExternalESModule;
5
- exports.virtualExternalCJSModule = virtualExternalCJSModule;
6
- exports.virtualPairComponent = virtualPairComponent;
7
- exports.fastbootSwitch = fastbootSwitch;
8
- exports.decodeFastbootSwitch = decodeFastbootSwitch;
9
- exports.decodeImplicitModules = decodeImplicitModules;
10
7
  const path_1 = require("path");
11
8
  const _1 = require(".");
12
9
  const js_handlebars_1 = require("./js-handlebars");
13
- const externalESPrefix = '/@embroider/ext-es/';
14
- const externalCJSPrefix = '/@embroider/ext-cjs/';
10
+ const virtual_test_support_1 = require("./virtual-test-support");
11
+ const virtual_test_support_styles_1 = require("./virtual-test-support-styles");
12
+ const virtual_vendor_1 = require("./virtual-vendor");
13
+ const virtual_vendor_styles_1 = require("./virtual-vendor-styles");
14
+ const virtual_entrypoint_1 = require("./virtual-entrypoint");
15
+ const virtual_route_entrypoint_1 = require("./virtual-route-entrypoint");
16
+ const assert_never_1 = __importDefault(require("assert-never"));
15
17
  // Given a filename that was passed to your ModuleRequest's `virtualize()`,
16
18
  // this produces the corresponding contents. It's a static, stateless function
17
19
  // because we recognize that that process that did resolution might not be the
18
20
  // same one that loads the content.
19
- function virtualContent(filename, resolver) {
20
- let cjsExtern = decodeVirtualExternalCJSModule(filename);
21
- if (cjsExtern) {
22
- return renderCJSExternalShim(cjsExtern);
23
- }
24
- let extern = decodeVirtualExternalESModule(filename);
25
- if (extern) {
26
- return renderESExternalShim(extern);
27
- }
28
- let match = decodeVirtualPairComponent(filename);
29
- if (match) {
30
- return pairedComponentShim(match);
31
- }
32
- let fb = decodeFastbootSwitch(filename);
33
- if (fb) {
34
- return fastbootSwitchTemplate(fb);
35
- }
36
- let im = decodeImplicitModules(filename);
37
- if (im) {
38
- return renderImplicitModules(im, resolver);
39
- }
40
- throw new Error(`not an @embroider/core virtual file: ${filename}`);
41
- }
42
- const externalESShim = (0, js_handlebars_1.compile)(`
43
- {{#if (eq moduleName "require")}}
44
- const m = window.requirejs;
45
- export default m;
46
- const has = m.has;
47
- export { has }
48
- {{else}}
49
- const m = window.require("{{{js-string-escape moduleName}}}");
50
- {{#if default}}
51
- export default m.default;
52
- {{/if}}
53
- {{#if names}}
54
- const { {{#each names as |name|}}{{name}}, {{/each}} } = m;
55
- export { {{#each names as |name|}}{{name}}, {{/each}} }
56
- {{/if}}
57
- {{/if}}
58
- `);
59
- function renderESExternalShim({ moduleName, exports }) {
60
- return externalESShim({
61
- moduleName,
62
- default: exports.includes('default'),
63
- names: exports.filter(n => n !== 'default'),
64
- });
21
+ function virtualContent(response, resolver) {
22
+ switch (response.type) {
23
+ case 'entrypoint':
24
+ return (0, virtual_entrypoint_1.renderEntrypoint)(resolver, response);
25
+ case 'vendor-js':
26
+ return (0, virtual_vendor_1.renderVendor)(response, resolver);
27
+ case 'vendor-css':
28
+ return (0, virtual_vendor_styles_1.renderVendorStyles)(response, resolver);
29
+ case 'test-support-css':
30
+ return (0, virtual_test_support_styles_1.renderTestSupportStyles)(response, resolver);
31
+ case 'test-support-js':
32
+ return (0, virtual_test_support_1.renderImplicitTestScripts)(response, resolver);
33
+ case 'component-pair':
34
+ return pairedComponentShim(response);
35
+ case 'implicit-modules':
36
+ case 'implicit-test-modules':
37
+ return renderImplicitModules(response, resolver);
38
+ case 'route-entrypoint':
39
+ return (0, virtual_route_entrypoint_1.renderRouteEntrypoint)(response, resolver);
40
+ case 'fastboot-switch':
41
+ return renderFastbootSwitchTemplate(response);
42
+ case 'template-only-component-js':
43
+ return renderTemplateOnlyComponent(response);
44
+ default:
45
+ throw (0, assert_never_1.default)(response);
46
+ }
47
+ }
48
+ function pairedComponentShim(params) {
49
+ return {
50
+ src: pairedComponentShimTemplate(params),
51
+ watches: [],
52
+ };
65
53
  }
66
- const pairedComponentShim = (0, js_handlebars_1.compile)(`
54
+ const pairedComponentShimTemplate = (0, js_handlebars_1.compile)(`
67
55
  import { setComponentTemplate } from "@ember/component";
68
- import template from "{{{js-string-escape relativeHBSModule}}}";
56
+ import template from "{{{js-string-escape hbsModule}}}";
69
57
  import { deprecate } from "@ember/debug";
70
58
 
71
59
 
@@ -82,96 +70,23 @@ deprecate("Components with separately resolved templates are deprecated. Migrate
82
70
  }
83
71
  );
84
72
 
85
- {{#if relativeJSModule}}
86
- import component from "{{{js-string-escape relativeJSModule}}}";
73
+ {{#if jsModule}}
74
+ import component from "{{{js-string-escape jsModule}}}";
87
75
  export default setComponentTemplate(template, component);
88
76
  {{else}}
89
77
  import templateOnlyComponent from "@ember/component/template-only";
90
78
  export default setComponentTemplate(template, templateOnlyComponent(undefined, "{{{js-string-escape debugName}}}"));
91
79
  {{/if}}
92
80
  `);
93
- function virtualExternalESModule(specifier, exports) {
94
- if (exports) {
95
- return externalESPrefix + specifier + `?exports=${exports.join(',')}`;
96
- }
97
- else {
98
- return externalESPrefix + specifier;
99
- }
100
- }
101
- function virtualExternalCJSModule(specifier) {
102
- return externalCJSPrefix + specifier;
103
- }
104
- function decodeVirtualExternalESModule(filename) {
105
- if (filename.startsWith(externalESPrefix)) {
106
- let exports = [];
107
- let url = new URL(filename.slice(externalESPrefix.length), 'http://example.com');
108
- let nameString = url.searchParams.get('exports');
109
- if (nameString) {
110
- exports = nameString.split(',');
111
- }
112
- let moduleName = url.pathname.slice(1);
113
- return { moduleName, exports };
114
- }
115
- }
116
- function decodeVirtualExternalCJSModule(filename) {
117
- if (filename.startsWith(externalCJSPrefix)) {
118
- return { moduleName: filename.slice(externalCJSPrefix.length) };
119
- }
120
- }
121
- const pairComponentMarker = '-embroider-pair-component';
122
- const pairComponentPattern = /^(?<hbsModule>.*)\/(?<jsModule>[^\/]*)-embroider-pair-component$/;
123
- function virtualPairComponent(hbsModule, jsModule) {
124
- let relativeJSModule = '';
125
- if (jsModule) {
126
- relativeJSModule = (0, _1.explicitRelative)(hbsModule, jsModule);
127
- }
128
- return `${hbsModule}/${encodeURIComponent(relativeJSModule)}${pairComponentMarker}`;
129
- }
130
- function decodeVirtualPairComponent(filename) {
131
- // Performance: avoid paying regex exec cost unless needed
132
- if (!filename.includes(pairComponentMarker)) {
133
- return null;
134
- }
135
- let match = pairComponentPattern.exec(filename);
136
- if (!match) {
137
- return null;
138
- }
139
- let { hbsModule, jsModule } = match.groups;
140
- // target our real hbs module from our virtual module
141
- let relativeHBSModule = (0, _1.explicitRelative)((0, path_1.dirname)(filename), hbsModule);
81
+ function renderFastbootSwitchTemplate(params) {
142
82
  return {
143
- relativeHBSModule,
144
- relativeJSModule: decodeURIComponent(jsModule) || null,
145
- debugName: (0, path_1.basename)(relativeHBSModule).replace(/\.(js|hbs)$/, ''),
83
+ src: fastbootSwitchTemplate({
84
+ names: [...params.names].filter(name => name !== 'default'),
85
+ hasDefaultExport: params.names.has('default'),
86
+ }),
87
+ watches: [],
146
88
  };
147
89
  }
148
- const fastbootSwitchSuffix = '/embroider_fastboot_switch';
149
- const fastbootSwitchPattern = /(?<original>.+)\/embroider_fastboot_switch(?:\?names=(?<names>.+))?$/;
150
- function fastbootSwitch(specifier, fromFile, names) {
151
- let filename = `${(0, path_1.resolve)((0, path_1.dirname)(fromFile), specifier)}${fastbootSwitchSuffix}`;
152
- if (names.size > 0) {
153
- return `${filename}?names=${[...names].join(',')}`;
154
- }
155
- else {
156
- return filename;
157
- }
158
- }
159
- function decodeFastbootSwitch(filename) {
160
- var _a, _b, _c;
161
- // Performance: avoid paying regex exec cost unless needed
162
- if (!filename.includes(fastbootSwitchSuffix)) {
163
- return;
164
- }
165
- let match = fastbootSwitchPattern.exec(filename);
166
- if (match) {
167
- let names = (_c = (_b = (_a = match.groups) === null || _a === void 0 ? void 0 : _a.names) === null || _b === void 0 ? void 0 : _b.split(',')) !== null && _c !== void 0 ? _c : [];
168
- return {
169
- names: names.filter(name => name !== 'default'),
170
- hasDefaultExport: names.includes('default'),
171
- filename: match.groups.original,
172
- };
173
- }
174
- }
175
90
  const fastbootSwitchTemplate = (0, js_handlebars_1.compile)(`
176
91
  import { macroCondition, getGlobalConfig, importSync } from '@embroider/macros';
177
92
  let mod;
@@ -187,28 +102,14 @@ export default mod.default;
187
102
  export const {{name}} = mod.{{name}};
188
103
  {{/each}}
189
104
  `);
190
- const implicitModulesPattern = /(?<filename>.*)[\\/]-embroider-implicit-(?<test>test-)?modules\.js$/;
191
- function decodeImplicitModules(filename) {
192
- // Performance: avoid paying regex exec cost unless needed
193
- if (!filename.includes('-embroider-implicit-')) {
194
- return;
195
- }
196
- let m = implicitModulesPattern.exec(filename);
197
- if (m) {
198
- return {
199
- type: m.groups.test ? 'implicit-test-modules' : 'implicit-modules',
200
- fromFile: m.groups.filename,
201
- };
202
- }
203
- }
204
- function renderImplicitModules({ type, fromFile, }, resolver) {
105
+ function renderImplicitModules({ type, fromFile }, resolver) {
205
106
  let resolvableExtensionsPattern = (0, _1.extensionsPattern)(resolver.options.resolvableExtensions);
206
107
  const pkg = resolver.packageCache.ownerOfFile(fromFile);
207
108
  if (!(pkg === null || pkg === void 0 ? void 0 : pkg.isV2Ember())) {
208
109
  throw new Error(`bug: saw special implicit modules import in non-ember package at ${fromFile}`);
209
110
  }
210
- let lazyModules = [];
211
- let eagerModules = [];
111
+ let ownModules = [];
112
+ let dependencyModules = [];
212
113
  let deps = pkg.dependencies.sort(orderAddons);
213
114
  for (let dep of deps) {
214
115
  // anything that isn't a v2 ember package by this point is not an active
@@ -241,7 +142,7 @@ function renderImplicitModules({ type, fromFile, }, resolver) {
241
142
  runtime = renamedModules[runtimeRenameLookup];
242
143
  }
243
144
  runtime = runtime.split(path_1.sep).join('/');
244
- lazyModules.push({
145
+ ownModules.push({
245
146
  runtime,
246
147
  buildtime: path_1.posix.join(packageName, name),
247
148
  });
@@ -250,20 +151,32 @@ function renderImplicitModules({ type, fromFile, }, resolver) {
250
151
  // we don't recurse across an engine boundary. Engines import their own
251
152
  // implicit-modules.
252
153
  if (!dep.isEngine()) {
253
- eagerModules.push(path_1.posix.join(dep.name, `-embroider-${type}.js`));
154
+ dependencyModules.push(path_1.posix.join(dep.name, `-embroider-${type}.js`));
254
155
  }
255
156
  }
256
- return implicitModulesTemplate({ lazyModules, eagerModules });
157
+ return { src: implicitModulesTemplate({ ownModules, dependencyModules }), watches: [] };
257
158
  }
258
159
  const implicitModulesTemplate = (0, js_handlebars_1.compile)(`
259
- import { importSync as i } from '@embroider/macros';
260
- let d = window.define;
261
- {{#each lazyModules as |module|}}
262
- d("{{js-string-escape module.runtime}}", function(){ return i("{{js-string-escape module.buildtime}}");});
160
+
161
+
162
+ {{#each dependencyModules as |module index|}}
163
+ import dep{{index}} from "{{js-string-escape module}}";
263
164
  {{/each}}
264
- {{#each eagerModules as |module|}}
265
- import "{{js-string-escape module}}";
165
+
166
+ {{#each ownModules as |module index|}}
167
+ import * as own{{index}} from "{{js-string-escape module.buildtime}}";
266
168
  {{/each}}
169
+
170
+ export default Object.assign({},
171
+ {{#each dependencyModules as |module index|}}
172
+ dep{{index}},
173
+ {{/each}}
174
+ {
175
+ {{#each ownModules as |module index|}}
176
+ "{{js-string-escape module.runtime}}": own{{index}},
177
+ {{/each}}
178
+ }
179
+ );
267
180
  `);
268
181
  // meta['renamed-modules'] has mapping from classic filename to real filename.
269
182
  // This takes that and converts it to the inverst mapping from real import path
@@ -289,26 +202,12 @@ function orderAddons(depA, depB) {
289
202
  }
290
203
  return depAIdx - depBIdx;
291
204
  }
292
- const renderCJSExternalShim = (0, js_handlebars_1.compile)(`
293
- {{#if (eq moduleName "require")}}
294
- const m = window.requirejs;
295
- {{else}}
296
- const m = window.require("{{{js-string-escape moduleName}}}");
297
- {{/if}}
298
- {{!-
299
- There are plenty of hand-written AMD defines floating around
300
- that lack this, and they will break when other build systems
301
- encounter them.
302
-
303
- As far as I can tell, Ember's loader was already treating this
304
- case as a module, so in theory we aren't breaking anything by
305
- marking it as such when other packagers come looking.
306
-
307
- todo: get review on this part.
308
- -}}
309
- if (m.default && !m.__esModule) {
310
- m.__esModule = true;
205
+ function renderTemplateOnlyComponent({ specifier }) {
206
+ let watches = [specifier];
207
+ let hbs = (0, _1.syntheticJStoHBS)(specifier);
208
+ if (hbs) {
209
+ watches.push(hbs);
210
+ }
211
+ return { src: (0, _1.templateOnlyComponentSource)(), watches };
311
212
  }
312
- module.exports = m;
313
- `);
314
213
  //# sourceMappingURL=virtual-content.js.map