@embroider/core 3.4.20-unstable.aaeb674 → 3.4.20-unstable.b470496

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 (42) hide show
  1. package/package.json +5 -5
  2. package/src/index.d.ts +3 -3
  3. package/src/index.js +3 -3
  4. package/src/index.js.map +1 -1
  5. package/src/module-request.d.ts +43 -0
  6. package/src/module-request.js +91 -0
  7. package/src/module-request.js.map +1 -0
  8. package/src/module-resolver-options.d.ts +0 -2
  9. package/src/module-resolver-options.js +0 -3
  10. package/src/module-resolver-options.js.map +1 -1
  11. package/src/module-resolver.d.ts +1 -29
  12. package/src/module-resolver.js +125 -198
  13. package/src/module-resolver.js.map +1 -1
  14. package/src/node-resolve.d.ts +13 -16
  15. package/src/node-resolve.js +38 -57
  16. package/src/node-resolve.js.map +1 -1
  17. package/src/options.d.ts +0 -3
  18. package/src/options.js.map +1 -1
  19. package/src/virtual-content.d.ts +24 -12
  20. package/src/virtual-content.js +35 -218
  21. package/src/virtual-content.js.map +1 -1
  22. package/src/virtual-entrypoint.d.ts +4 -2
  23. package/src/virtual-entrypoint.js +2 -18
  24. package/src/virtual-entrypoint.js.map +1 -1
  25. package/src/virtual-route-entrypoint.d.ts +4 -9
  26. package/src/virtual-route-entrypoint.js +5 -44
  27. package/src/virtual-route-entrypoint.js.map +1 -1
  28. package/src/virtual-test-support-styles.d.ts +5 -2
  29. package/src/virtual-test-support-styles.js +2 -5
  30. package/src/virtual-test-support-styles.js.map +1 -1
  31. package/src/virtual-test-support.d.ts +5 -2
  32. package/src/virtual-test-support.js +2 -5
  33. package/src/virtual-test-support.js.map +1 -1
  34. package/src/virtual-vendor-styles.d.ts +5 -1
  35. package/src/virtual-vendor-styles.js +2 -1
  36. package/src/virtual-vendor-styles.js.map +1 -1
  37. package/src/virtual-vendor.d.ts +5 -2
  38. package/src/virtual-vendor.js +6 -25
  39. package/src/virtual-vendor.js.map +1 -1
  40. package/src/to-broccoli-plugin.d.ts +0 -8
  41. package/src/to-broccoli-plugin.js +0 -30
  42. package/src/to-broccoli-plugin.js.map +0 -1
@@ -3,70 +3,42 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.NodeModuleRequest = void 0;
6
+ exports.NodeRequestAdapter = void 0;
7
7
  exports.nodeResolve = nodeResolve;
8
8
  const virtual_content_1 = require("./virtual-content");
9
9
  const path_1 = require("path");
10
10
  const shared_internals_1 = require("@embroider/shared-internals");
11
11
  const assert_never_1 = __importDefault(require("assert-never"));
12
- class NodeModuleRequest {
13
- constructor(resolver, specifier, fromFile, isVirtual, meta, isNotFound, resolvedTo) {
12
+ // these would be circular, but they're type-only so it's fine
13
+ const module_request_1 = require("./module-request");
14
+ class NodeRequestAdapter {
15
+ constructor(resolver) {
14
16
  this.resolver = resolver;
15
- this.specifier = specifier;
16
- this.fromFile = fromFile;
17
- this.isVirtual = isVirtual;
18
- this.meta = meta;
19
- this.isNotFound = isNotFound;
20
- this.resolvedTo = resolvedTo;
21
17
  }
22
18
  get debugType() {
23
19
  return 'node';
24
20
  }
25
- alias(specifier) {
26
- return new NodeModuleRequest(this.resolver, specifier, this.fromFile, false, this.meta, false, undefined);
21
+ notFoundResponse(request) {
22
+ let err = new Error(`module not found ${request.specifier}`);
23
+ err.code = 'MODULE_NOT_FOUND';
24
+ return {
25
+ type: 'not_found',
26
+ err,
27
+ };
27
28
  }
28
- rehome(fromFile) {
29
- if (this.fromFile === fromFile) {
30
- return this;
31
- }
32
- else {
33
- return new NodeModuleRequest(this.resolver, this.specifier, fromFile, false, this.meta, false, undefined);
34
- }
35
- }
36
- virtualize(filename) {
37
- return new NodeModuleRequest(this.resolver, filename, this.fromFile, true, this.meta, false, undefined);
38
- }
39
- withMeta(meta) {
40
- return new NodeModuleRequest(this.resolver, this.specifier, this.fromFile, this.isVirtual, meta, this.isNotFound, this.resolvedTo);
41
- }
42
- notFound() {
43
- return new NodeModuleRequest(this.resolver, this.specifier, this.fromFile, this.isVirtual, this.meta, true, undefined);
29
+ virtualResponse(_request, virtual) {
30
+ return {
31
+ type: 'found',
32
+ filename: virtual.specifier,
33
+ virtual,
34
+ result: {
35
+ type: 'virtual',
36
+ content: (0, virtual_content_1.virtualContent)(virtual, this.resolver).src,
37
+ filename: virtual.specifier,
38
+ },
39
+ };
44
40
  }
45
- resolveTo(resolution) {
46
- return new NodeModuleRequest(this.resolver, this.specifier, this.fromFile, this.isVirtual, this.meta, this.isNotFound, resolution);
47
- }
48
- async defaultResolve() {
49
- const request = this;
50
- if (request.isVirtual) {
51
- return {
52
- type: 'found',
53
- filename: request.specifier,
54
- isVirtual: true,
55
- result: {
56
- type: 'virtual',
57
- content: (0, virtual_content_1.virtualContent)(request.specifier, this.resolver).src,
58
- filename: request.specifier,
59
- },
60
- };
61
- }
62
- if (request.isNotFound) {
63
- let err = new Error(`module not found ${request.specifier}`);
64
- err.code = 'MODULE_NOT_FOUND';
65
- return {
66
- type: 'not_found',
67
- err,
68
- };
69
- }
41
+ async resolve(request) {
70
42
  // require.resolve does not like when we resolve from virtual paths.
71
43
  // That is, a request like "../thing.js" from
72
44
  // "/a/real/path/VIRTUAL_SUBDIR/virtual.js" has an unambiguous target of
@@ -102,12 +74,22 @@ class NodeModuleRequest {
102
74
  }
103
75
  continue;
104
76
  }
105
- return { type: 'found', filename, result: { type: 'real', filename }, isVirtual: false };
77
+ return { type: 'found', filename, result: { type: 'real', filename }, virtual: false };
106
78
  }
107
79
  return { type: 'not_found', err: initialError };
108
80
  }
109
81
  }
110
- exports.NodeModuleRequest = NodeModuleRequest;
82
+ exports.NodeRequestAdapter = NodeRequestAdapter;
83
+ NodeRequestAdapter.create = ({ resolver, specifier, fromFile }) => {
84
+ return {
85
+ initialState: {
86
+ specifier,
87
+ fromFile,
88
+ meta: undefined,
89
+ },
90
+ adapter: new NodeRequestAdapter(resolver),
91
+ };
92
+ };
111
93
  function* candidates(specifier) {
112
94
  yield specifier;
113
95
  const extensions = ['.hbs.js', '.hbs'];
@@ -116,14 +98,13 @@ function* candidates(specifier) {
116
98
  }
117
99
  }
118
100
  async function nodeResolve(resolver, specifier, fromFile) {
119
- let resolution = await resolver.resolve(new NodeModuleRequest(resolver, specifier, fromFile, false, undefined, false, undefined));
101
+ let request = module_request_1.ModuleRequest.create(NodeRequestAdapter.create, { resolver, fromFile, specifier });
102
+ let resolution = await resolver.resolve(request);
120
103
  switch (resolution.type) {
121
104
  case 'not_found':
122
105
  return resolution;
123
106
  case 'found':
124
107
  return resolution.result;
125
- case 'ignored':
126
- throw new Error(`bug: this is supposed to be impossible because NodeModuleRequest.prototype.defaultResove does not use "ignored"`);
127
108
  default:
128
109
  throw (0, assert_never_1.default)(resolution);
129
110
  }
@@ -1 +1 @@
1
- {"version":3,"file":"node-resolve.js","sourceRoot":"","sources":["node-resolve.ts"],"names":[],"mappings":";;;;;;AAyJA,kCAoBC;AA7KD,uDAAmD;AACnD,+BAAoD;AACpD,kEAA+D;AAC/D,gEAAuC;AAKvC,MAAa,iBAAiB;IAC5B,YACU,QAAkB,EACjB,SAAiB,EACjB,QAAgB,EAChB,SAAkB,EAClB,IAAqC,EACrC,UAAmB,EACnB,UAAyD;QAN1D,aAAQ,GAAR,QAAQ,CAAU;QACjB,cAAS,GAAT,SAAS,CAAQ;QACjB,aAAQ,GAAR,QAAQ,CAAQ;QAChB,cAAS,GAAT,SAAS,CAAS;QAClB,SAAI,GAAJ,IAAI,CAAiC;QACrC,eAAU,GAAV,UAAU,CAAS;QACnB,eAAU,GAAV,UAAU,CAA+C;IACjE,CAAC;IAEJ,IAAI,SAAS;QACX,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,KAAK,CAAC,SAAiB;QACrB,OAAO,IAAI,iBAAiB,CAAC,IAAI,CAAC,QAAQ,EAAE,SAAS,EAAE,IAAI,CAAC,QAAQ,EAAE,KAAK,EAAE,IAAI,CAAC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AAE,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,CAAC,CACzF,CAAC;IACF,QAAQ,UAAU,CAAC,IAAI,EAAE,CAAC;QACxB,KAAK,WAAW;YACd,OAAO,UAAU,CAAC;QACpB,KAAK,OAAO;YACV,OAAO,UAAU,CAAC,MAAM,CAAC;QAC3B,KAAK,SAAS;YACZ,MAAM,IAAI,KAAK,CACb,iHAAiH,CAClH,CAAC;QACJ;YACE,MAAM,IAAA,sBAAW,EAAC,UAAU,CAAC,CAAC;IAClC,CAAC;AACH,CAAC","sourcesContent":["import { virtualContent } 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 type { ModuleRequest, Resolution, Resolver } from './module-resolver';\n\nexport class NodeModuleRequest implements ModuleRequest {\n constructor(\n private resolver: Resolver,\n readonly specifier: string,\n readonly fromFile: string,\n readonly isVirtual: boolean,\n readonly meta: Record<string, any> | undefined,\n readonly isNotFound: boolean,\n readonly resolvedTo: Resolution<NodeResolution, Error> | undefined\n ) {}\n\n get debugType() {\n return 'node';\n }\n\n alias(specifier: string): this {\n return new NodeModuleRequest(this.resolver, specifier, this.fromFile, false, this.meta, false, undefined) as this;\n }\n rehome(fromFile: string): this {\n if (this.fromFile === fromFile) {\n return this;\n } else {\n return new NodeModuleRequest(this.resolver, this.specifier, fromFile, false, this.meta, false, undefined) as this;\n }\n }\n virtualize(filename: string): this {\n return new NodeModuleRequest(this.resolver, filename, this.fromFile, true, this.meta, false, undefined) as this;\n }\n withMeta(meta: Record<string, any> | undefined): this {\n return new NodeModuleRequest(\n this.resolver,\n this.specifier,\n this.fromFile,\n this.isVirtual,\n meta,\n this.isNotFound,\n this.resolvedTo\n ) as this;\n }\n notFound(): this {\n return new NodeModuleRequest(\n this.resolver,\n this.specifier,\n this.fromFile,\n this.isVirtual,\n this.meta,\n true,\n undefined\n ) as this;\n }\n\n resolveTo(resolution: Resolution<NodeResolution, Error>): this {\n return new NodeModuleRequest(\n this.resolver,\n this.specifier,\n this.fromFile,\n this.isVirtual,\n this.meta,\n this.isNotFound,\n resolution\n ) as this;\n }\n\n async defaultResolve(): Promise<Resolution<NodeResolution, Error>> {\n const request = this;\n if (request.isVirtual) {\n return {\n type: 'found',\n filename: request.specifier,\n isVirtual: true,\n result: {\n type: 'virtual' as 'virtual',\n content: virtualContent(request.specifier, this.resolver).src,\n filename: request.specifier,\n },\n };\n }\n if (request.isNotFound) {\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 // 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)) {\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 return { type: 'found', filename, result: { type: 'real' as 'real', filename }, isVirtual: false };\n }\n\n return { type: 'not_found', err: initialError };\n }\n}\n\nfunction* candidates(specifier: string) {\n yield specifier;\n\n const extensions = ['.hbs.js', '.hbs'];\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 async function nodeResolve(\n resolver: Resolver,\n specifier: string,\n fromFile: string\n): Promise<NodeResolution | NodeResolutionError> {\n let resolution = await resolver.resolve(\n new NodeModuleRequest(resolver, specifier, fromFile, false, undefined, false, undefined)\n );\n switch (resolution.type) {\n case 'not_found':\n return resolution;\n case 'found':\n return resolution.result;\n case 'ignored':\n throw new Error(\n `bug: this is supposed to be impossible because NodeModuleRequest.prototype.defaultResove does not use \"ignored\"`\n );\n default:\n throw assertNever(resolution);\n }\n}\n"]}
1
+ {"version":3,"file":"node-resolve.js","sourceRoot":"","sources":["node-resolve.ts"],"names":[],"mappings":";;;;;;AAmHA,kCAeC;AAlID,uDAAyE;AACzE,+BAAoD;AACpD,kEAA+D;AAC/D,gEAAuC;AAEvC,8DAA8D;AAC9D,qDAAkH;AAGlH,MAAa,kBAAkB;IAe7B,YAA4B,QAAkB;QAAlB,aAAQ,GAAR,QAAQ,CAAU;IAAG,CAAC;IAElD,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,GAAW,CAAC,IAAI,GAAG,kBAAkB,CAAC;QACvC,OAAO;YACL,IAAI,EAAE,WAAW;YACjB,GAAG;SACJ,CAAC;IACJ,CAAC;IAED,eAAe,CACb,QAA0D,EAC1D,OAAwB;QAExB,OAAO;YACL,IAAI,EAAE,OAAO;YACb,QAAQ,EAAE,OAAO,CAAC,SAAS;YAC3B,OAAO;YACP,MAAM,EAAE;gBACN,IAAI,EAAE,SAAkB;gBACxB,OAAO,EAAE,IAAA,gCAAc,EAAC,OAAO,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC,GAAG;gBACnD,QAAQ,EAAE,OAAO,CAAC,SAAS;aAC5B;SACF,CAAC;IACJ,CAAC;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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 },\n Resolution<NodeResolution, Error>\n > = ({ resolver, specifier, fromFile }) => {\n return {\n initialState: {\n specifier,\n fromFile,\n meta: undefined,\n },\n adapter: new NodeRequestAdapter(resolver),\n };\n };\n\n private constructor(private resolver: Resolver) {}\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)) {\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 return { type: 'found', filename, result: { type: 'real' as 'real', filename }, virtual: false };\n }\n\n return { type: 'not_found', err: initialError };\n }\n}\n\nfunction* candidates(specifier: string) {\n yield specifier;\n\n const extensions = ['.hbs.js', '.hbs'];\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 async function nodeResolve(\n resolver: Resolver,\n specifier: string,\n fromFile: string\n): Promise<NodeResolution | NodeResolutionError> {\n let request = ModuleRequest.create(NodeRequestAdapter.create, { resolver, fromFile, specifier });\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
@@ -8,8 +8,5 @@ export default interface Options {
8
8
  resolve: string[];
9
9
  useMethod?: string;
10
10
  }[];
11
- amdCompatibility?: false | 'cjs' | {
12
- es: [string, string[]][];
13
- };
14
11
  }
15
12
  export declare function optionsWithDefaults(options?: Options): Required<Options>;
@@ -1 +1 @@
1
- {"version":3,"file":"options.js","sourceRoot":"","sources":["options.ts"],"names":[],"mappings":";;AAsHA,kDAcC;AAdD,SAAgB,mBAAmB,CAAC,OAAiB;IACnD,IAAI,QAAQ,GAAG;QACb,aAAa,EAAE,KAAK;QACpB,eAAe,EAAE,KAAK;QACtB,gBAAgB,EAAE,KAAK;QACvB,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 // 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 staticHelpers?: boolean;\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 staticModifiers?: boolean;\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 staticComponents?: 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 // 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 function optionsWithDefaults(options?: Options): Required<Options> {\n let defaults = {\n staticHelpers: false,\n staticModifiers: false,\n staticComponents: false,\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"]}
1
+ {"version":3,"file":"options.js","sourceRoot":"","sources":["options.ts"],"names":[],"mappings":";;AA2EA,kDAcC;AAdD,SAAgB,mBAAmB,CAAC,OAAiB;IACnD,IAAI,QAAQ,GAAG;QACb,aAAa,EAAE,KAAK;QACpB,eAAe,EAAE,KAAK;QACtB,gBAAgB,EAAE,KAAK;QACvB,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 // 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 staticHelpers?: boolean;\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 staticModifiers?: boolean;\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 staticComponents?: 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 function optionsWithDefaults(options?: Options): Required<Options> {\n let defaults = {\n staticHelpers: false,\n staticModifiers: false,\n staticComponents: false,\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"]}
@@ -1,19 +1,31 @@
1
1
  import type { Resolver } from '.';
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);
2
11
  export interface VirtualContentResult {
3
12
  src: string;
4
13
  watches: string[];
5
14
  }
6
- export declare function virtualContent(filename: string, resolver: Resolver): VirtualContentResult;
7
- export declare function virtualExternalESModule(specifier: string, exports: string[] | undefined): string;
8
- export declare function virtualExternalCJSModule(specifier: string): string;
9
- export declare function virtualPairComponent(hbsModule: string, jsModule: string | undefined): string;
10
- export declare function fastbootSwitch(specifier: string, fromFile: string, names: Set<string>): string;
11
- export declare function decodeFastbootSwitch(filename: string): {
12
- names: string[];
13
- hasDefaultExport: boolean;
14
- filename: string;
15
- } | undefined;
16
- export declare function decodeImplicitModules(filename: string): {
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 {
17
28
  type: 'implicit-modules' | 'implicit-test-modules';
18
29
  fromFile: string;
19
- } | undefined;
30
+ }
31
+ export {};
@@ -1,12 +1,9 @@
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");
@@ -16,85 +13,35 @@ const virtual_vendor_1 = require("./virtual-vendor");
16
13
  const virtual_vendor_styles_1 = require("./virtual-vendor-styles");
17
14
  const virtual_entrypoint_1 = require("./virtual-entrypoint");
18
15
  const virtual_route_entrypoint_1 = require("./virtual-route-entrypoint");
19
- const externalESPrefix = '/@embroider/ext-es/';
20
- const externalCJSPrefix = '/@embroider/ext-cjs/';
16
+ const assert_never_1 = __importDefault(require("assert-never"));
21
17
  // Given a filename that was passed to your ModuleRequest's `virtualize()`,
22
18
  // this produces the corresponding contents. It's a static, stateless function
23
19
  // because we recognize that that process that did resolution might not be the
24
20
  // same one that loads the content.
25
- function virtualContent(filename, resolver) {
26
- let cjsExtern = decodeVirtualExternalCJSModule(filename);
27
- if (cjsExtern) {
28
- return renderCJSExternalShim(cjsExtern);
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
+ default:
43
+ throw (0, assert_never_1.default)(response);
29
44
  }
30
- let entrypoint = (0, virtual_entrypoint_1.decodeEntrypoint)(filename);
31
- if (entrypoint) {
32
- return (0, virtual_entrypoint_1.renderEntrypoint)(resolver, entrypoint);
33
- }
34
- let routeEntrypoint = (0, virtual_route_entrypoint_1.decodeRouteEntrypoint)(filename);
35
- if (routeEntrypoint) {
36
- return (0, virtual_route_entrypoint_1.renderRouteEntrypoint)(resolver, routeEntrypoint);
37
- }
38
- let extern = decodeVirtualExternalESModule(filename);
39
- if (extern) {
40
- return renderESExternalShim(extern);
41
- }
42
- let match = decodeVirtualPairComponent(filename);
43
- if (match) {
44
- return pairedComponentShim(match);
45
- }
46
- let fb = decodeFastbootSwitch(filename);
47
- if (fb) {
48
- return renderFastbootSwitchTemplate(fb);
49
- }
50
- let im = decodeImplicitModules(filename);
51
- if (im) {
52
- return renderImplicitModules(im, resolver);
53
- }
54
- let isVendor = (0, virtual_vendor_1.decodeVirtualVendor)(filename);
55
- if (isVendor) {
56
- return (0, virtual_vendor_1.renderVendor)(filename, resolver);
57
- }
58
- let isImplicitTestScripts = (0, virtual_test_support_1.decodeImplicitTestScripts)(filename);
59
- if (isImplicitTestScripts) {
60
- return (0, virtual_test_support_1.renderImplicitTestScripts)(filename, resolver);
61
- }
62
- let isVendorStyles = (0, virtual_vendor_styles_1.decodeVirtualVendorStyles)(filename);
63
- if (isVendorStyles) {
64
- return (0, virtual_vendor_styles_1.renderVendorStyles)(filename, resolver);
65
- }
66
- let isTestSupportStyles = (0, virtual_test_support_styles_1.decodeTestSupportStyles)(filename);
67
- if (isTestSupportStyles) {
68
- return (0, virtual_test_support_styles_1.renderTestSupportStyles)(filename, resolver);
69
- }
70
- throw new Error(`not an @embroider/core virtual file: ${filename}`);
71
- }
72
- const externalESShim = (0, js_handlebars_1.compile)(`
73
- {{#if (eq moduleName "require")}}
74
- const m = window.requirejs;
75
- export default m;
76
- const has = m.has;
77
- export { has }
78
- {{else}}
79
- const m = window.require("{{{js-string-escape moduleName}}}");
80
- {{#if default}}
81
- export default m.default;
82
- {{/if}}
83
- {{#if names}}
84
- const { {{#each names as |name|}}{{name}}, {{/each}} } = m;
85
- export { {{#each names as |name|}}{{name}}, {{/each}} }
86
- {{/if}}
87
- {{/if}}
88
- `);
89
- function renderESExternalShim({ moduleName, exports, }) {
90
- return {
91
- src: externalESShim({
92
- moduleName,
93
- default: exports.includes('default'),
94
- names: exports.filter(n => n !== 'default'),
95
- }),
96
- watches: [],
97
- };
98
45
  }
99
46
  function pairedComponentShim(params) {
100
47
  return {
@@ -104,7 +51,7 @@ function pairedComponentShim(params) {
104
51
  }
105
52
  const pairedComponentShimTemplate = (0, js_handlebars_1.compile)(`
106
53
  import { setComponentTemplate } from "@ember/component";
107
- import template from "{{{js-string-escape relativeHBSModule}}}";
54
+ import template from "{{{js-string-escape hbsModule}}}";
108
55
  import { deprecate } from "@ember/debug";
109
56
 
110
57
 
@@ -121,99 +68,20 @@ deprecate("Components with separately resolved templates are deprecated. Migrate
121
68
  }
122
69
  );
123
70
 
124
- {{#if relativeJSModule}}
125
- import component from "{{{js-string-escape relativeJSModule}}}";
71
+ {{#if jsModule}}
72
+ import component from "{{{js-string-escape jsModule}}}";
126
73
  export default setComponentTemplate(template, component);
127
74
  {{else}}
128
75
  import templateOnlyComponent from "@ember/component/template-only";
129
76
  export default setComponentTemplate(template, templateOnlyComponent(undefined, "{{{js-string-escape debugName}}}"));
130
77
  {{/if}}
131
78
  `);
132
- function virtualExternalESModule(specifier, exports) {
133
- if (exports) {
134
- return externalESPrefix + specifier + `/exports=${exports.join(',')}`;
135
- }
136
- else {
137
- return externalESPrefix + specifier;
138
- }
139
- }
140
- function virtualExternalCJSModule(specifier) {
141
- return externalCJSPrefix + specifier;
142
- }
143
- function decodeVirtualExternalESModule(filename) {
144
- if (filename.startsWith(externalESPrefix)) {
145
- let exports = [];
146
- let components = filename.split('/exports=');
147
- let nameString = components[1];
148
- if (nameString) {
149
- exports = nameString.split(',');
150
- }
151
- let moduleName = components[0].slice(externalESPrefix.length);
152
- return { moduleName, exports };
153
- }
154
- }
155
- function decodeVirtualExternalCJSModule(filename) {
156
- if (filename.startsWith(externalCJSPrefix)) {
157
- return { moduleName: filename.slice(externalCJSPrefix.length) };
158
- }
159
- }
160
- const pairComponentMarker = '-embroider-pair-component';
161
- const pairComponentPattern = /^(?<hbsModule>.*)__vpc__(?<jsModule>[^\/]*)-embroider-pair-component$/;
162
- function virtualPairComponent(hbsModule, jsModule) {
163
- let relativeJSModule = '';
164
- if (jsModule) {
165
- relativeJSModule = (0, _1.explicitRelative)((0, path_1.dirname)(hbsModule), jsModule);
166
- }
167
- return `${hbsModule}__vpc__${encodeURIComponent(relativeJSModule)}${pairComponentMarker}`;
168
- }
169
- function decodeVirtualPairComponent(filename) {
170
- // Performance: avoid paying regex exec cost unless needed
171
- if (!filename.includes(pairComponentMarker)) {
172
- return null;
173
- }
174
- let match = pairComponentPattern.exec(filename);
175
- if (!match) {
176
- return null;
177
- }
178
- let { hbsModule, jsModule } = match.groups;
179
- // target our real hbs module from our virtual module
180
- let relativeHBSModule = (0, _1.explicitRelative)((0, path_1.dirname)(filename), hbsModule);
181
- return {
182
- relativeHBSModule,
183
- relativeJSModule: decodeURIComponent(jsModule) || null,
184
- debugName: (0, path_1.basename)(relativeHBSModule).replace(/\.(js|hbs)$/, ''),
185
- };
186
- }
187
- const fastbootSwitchSuffix = '/embroider_fastboot_switch';
188
- const fastbootSwitchPattern = /(?<original>.+)\/embroider_fastboot_switch(?:\?names=(?<names>.+))?$/;
189
- function fastbootSwitch(specifier, fromFile, names) {
190
- let filename = `${(0, path_1.resolve)((0, path_1.dirname)(fromFile), specifier)}${fastbootSwitchSuffix}`;
191
- if (names.size > 0) {
192
- return `${filename}?names=${[...names].join(',')}`;
193
- }
194
- else {
195
- return filename;
196
- }
197
- }
198
- function decodeFastbootSwitch(filename) {
199
- var _a, _b, _c;
200
- // Performance: avoid paying regex exec cost unless needed
201
- if (!filename.includes(fastbootSwitchSuffix)) {
202
- return;
203
- }
204
- let match = fastbootSwitchPattern.exec(filename);
205
- if (match) {
206
- 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 : [];
207
- return {
208
- names: names.filter(name => name !== 'default'),
209
- hasDefaultExport: names.includes('default'),
210
- filename: match.groups.original,
211
- };
212
- }
213
- }
214
79
  function renderFastbootSwitchTemplate(params) {
215
80
  return {
216
- src: fastbootSwitchTemplate(params),
81
+ src: fastbootSwitchTemplate({
82
+ names: [...params.names].filter(name => name !== 'default'),
83
+ hasDefaultExport: params.names.has('default'),
84
+ }),
217
85
  watches: [],
218
86
  };
219
87
  }
@@ -232,21 +100,7 @@ export default mod.default;
232
100
  export const {{name}} = mod.{{name}};
233
101
  {{/each}}
234
102
  `);
235
- const implicitModulesPattern = /(?<filename>.*)[\\/]-embroider-implicit-(?<test>test-)?modules\.js$/;
236
- function decodeImplicitModules(filename) {
237
- // Performance: avoid paying regex exec cost unless needed
238
- if (!filename.includes('-embroider-implicit-')) {
239
- return;
240
- }
241
- let m = implicitModulesPattern.exec(filename);
242
- if (m) {
243
- return {
244
- type: m.groups.test ? 'implicit-test-modules' : 'implicit-modules',
245
- fromFile: m.groups.filename,
246
- };
247
- }
248
- }
249
- function renderImplicitModules({ type, fromFile, }, resolver) {
103
+ function renderImplicitModules({ type, fromFile }, resolver) {
250
104
  let resolvableExtensionsPattern = (0, _1.extensionsPattern)(resolver.options.resolvableExtensions);
251
105
  const pkg = resolver.packageCache.ownerOfFile(fromFile);
252
106
  if (!(pkg === null || pkg === void 0 ? void 0 : pkg.isV2Ember())) {
@@ -346,41 +200,4 @@ function orderAddons(depA, depB) {
346
200
  }
347
201
  return depAIdx - depBIdx;
348
202
  }
349
- function renderCJSExternalShim(params) {
350
- return {
351
- src: renderCJSExternalShimTemplate(params),
352
- watches: [],
353
- };
354
- }
355
- const renderCJSExternalShimTemplate = (0, js_handlebars_1.compile)(`
356
- module.exports = new Proxy({}, {
357
- get(target, prop) {
358
-
359
- {{!- our proxy always presents as ES module so that we can intercept "get('default')" -}}
360
- if (prop === '__esModule') {
361
- return true;
362
- }
363
-
364
- {{#if (eq moduleName "require")}}
365
- const m = window.requirejs;
366
- {{else}}
367
- const m = window.require("{{{js-string-escape moduleName}}}");
368
- {{/if}}
369
-
370
- {{!-
371
- There are plenty of hand-written AMD defines floating around
372
- that lack an __esModule declaration.
373
-
374
- As far as I can tell, Ember's loader was already treating the Boolean(m.default)===true
375
- case as a module, so in theory we aren't breaking anything by
376
- treating it as such when other packagers come looking.
377
- -}}
378
- if (prop === 'default' && !m.__esModule && !m.default) {
379
- return m;
380
- }
381
-
382
- return m[prop];
383
- }
384
- });
385
- `);
386
203
  //# sourceMappingURL=virtual-content.js.map