@embroider/vite 0.2.0 → 0.2.1-unstable.024270b

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.
package/src/hbs.js CHANGED
@@ -1,57 +1,80 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.hbs = void 0;
7
- // TODO: I copied this from @embroider/addon-dev, it needs to be its own package
8
- // (or be in shared-internals or core)
3
+ exports.hbs = hbs;
9
4
  const pluginutils_1 = require("@rollup/pluginutils");
10
- const fs_1 = require("fs");
11
5
  const core_1 = require("@embroider/core");
12
- const assert_never_1 = __importDefault(require("assert-never"));
13
- const path_1 = require("path");
14
- const debug_1 = __importDefault(require("debug"));
15
- const debug = (0, debug_1.default)('embroider:hbs-plugin');
6
+ const resolverLoader = new core_1.ResolverLoader(process.cwd());
7
+ const hbsFilter = (0, pluginutils_1.createFilter)('**/*.hbs?([?]*)');
16
8
  function hbs() {
17
9
  return {
18
10
  name: 'rollup-hbs-plugin',
19
11
  enforce: 'pre',
20
- async resolveId(source, importer) {
12
+ async resolveId(source, importer, options) {
13
+ var _a, _b, _c;
14
+ if ((_a = options.custom) === null || _a === void 0 ? void 0 : _a.depScan) {
15
+ // during depscan we have a corresponding esbuild plugin that is
16
+ // responsible for this stuff instead. We don't want to fight with it.
17
+ return null;
18
+ }
19
+ if ((_c = (_b = options.custom) === null || _b === void 0 ? void 0 : _b.embroider) === null || _c === void 0 ? void 0 : _c.isExtensionSearch) {
20
+ return null;
21
+ }
21
22
  let resolution = await this.resolve(source, importer, {
22
23
  skipSelf: true,
23
24
  });
24
25
  if (!resolution) {
25
- return maybeSynthesizeComponentJS(this, source, importer);
26
+ let hbsSource = (0, core_1.syntheticJStoHBS)(source);
27
+ if (hbsSource) {
28
+ resolution = await this.resolve(hbsSource, importer, {
29
+ skipSelf: true,
30
+ custom: {
31
+ embroider: {
32
+ // we don't want to recurse into the whole embroider compatbility
33
+ // resolver here. It has presumably already steered our request to the
34
+ // correct place. All we want to do is slightly modify the request we
35
+ // were given (changing the extension) and check if that would resolve
36
+ // instead.
37
+ //
38
+ // Currently this guard is only actually exercised in rollup, not in
39
+ // vite, due to https://github.com/vitejs/vite/issues/13852
40
+ enableCustomResolver: false,
41
+ isExtensionSearch: true,
42
+ },
43
+ },
44
+ });
45
+ }
46
+ if (!resolution) {
47
+ return null;
48
+ }
26
49
  }
27
- else {
28
- return maybeRewriteHBS(resolution);
50
+ let syntheticId = (0, core_1.needsSyntheticComponentJS)(source, resolution.id, resolverLoader.resolver.packageCache);
51
+ if (syntheticId) {
52
+ return {
53
+ id: syntheticId,
54
+ meta: {
55
+ 'rollup-hbs-plugin': {
56
+ type: 'template-only-component-js',
57
+ },
58
+ },
59
+ };
29
60
  }
30
61
  },
31
62
  load(id) {
32
- const meta = getMeta(this, id);
33
- if (!meta) {
34
- return;
63
+ var _a;
64
+ if (((_a = getMeta(this, id)) === null || _a === void 0 ? void 0 : _a.type) === 'template-only-component-js') {
65
+ return {
66
+ code: (0, core_1.templateOnlyComponentSource)(),
67
+ };
35
68
  }
36
- switch (meta.type) {
37
- case 'template':
38
- let input = (0, fs_1.readFileSync)(id, 'utf8');
39
- let code = (0, core_1.hbsToJS)(input);
40
- return {
41
- code,
42
- };
43
- case 'template-only-component-js':
44
- return {
45
- code: templateOnlyComponent,
46
- };
47
- default:
48
- (0, assert_never_1.default)(meta);
69
+ },
70
+ transform(code, id) {
71
+ if (!hbsFilter(id)) {
72
+ return null;
49
73
  }
74
+ return (0, core_1.hbsToJS)(code);
50
75
  },
51
76
  };
52
77
  }
53
- exports.hbs = hbs;
54
- const templateOnlyComponent = `import templateOnly from '@ember/component/template-only';\n` + `export default templateOnly();\n`;
55
78
  function getMeta(context, id) {
56
79
  var _a, _b;
57
80
  const meta = (_b = (_a = context.getModuleInfo(id)) === null || _a === void 0 ? void 0 : _a.meta) === null || _b === void 0 ? void 0 : _b['rollup-hbs-plugin'];
@@ -62,56 +85,4 @@ function getMeta(context, id) {
62
85
  return null;
63
86
  }
64
87
  }
65
- function correspondingTemplate(filename) {
66
- let { ext } = (0, path_1.parse)(filename);
67
- return filename.slice(0, filename.length - ext.length) + '.hbs';
68
- }
69
- async function maybeSynthesizeComponentJS(context, source, importer) {
70
- debug(`checking for template-only component: %s`, source);
71
- let templateResolution = await context.resolve(correspondingTemplate(source), importer, {
72
- skipSelf: true,
73
- custom: {
74
- embroider: {
75
- // we don't want to recurse into the whole embroider compatbility
76
- // resolver here. It has presumably already steered our request to the
77
- // correct place. All we want to do is slightly modify the request we
78
- // were given (changing the extension) and check if that would resolve
79
- // instead.
80
- //
81
- // Currently this guard is only actually exercised in rollup, not in
82
- // vite, due to https://github.com/vitejs/vite/issues/13852
83
- enableCustomResolver: false,
84
- },
85
- },
86
- });
87
- if (!templateResolution) {
88
- return null;
89
- }
90
- debug(`emitting template only component: %s`, templateResolution.id);
91
- // we're trying to resolve a JS module but only the corresponding HBS
92
- // file exists. Synthesize the template-only component JS.
93
- return {
94
- id: templateResolution.id.replace(/\.hbs$/, '.js'),
95
- meta: {
96
- 'rollup-hbs-plugin': {
97
- type: 'template-only-component-js',
98
- },
99
- },
100
- };
101
- }
102
- const hbsFilter = (0, pluginutils_1.createFilter)('**/*.hbs');
103
- function maybeRewriteHBS(resolution) {
104
- if (!hbsFilter(resolution.id)) {
105
- return null;
106
- }
107
- debug('emitting hbs rewrite: %s', resolution.id);
108
- return {
109
- ...resolution,
110
- meta: {
111
- 'rollup-hbs-plugin': {
112
- type: 'template',
113
- },
114
- },
115
- };
116
- }
117
88
  //# sourceMappingURL=hbs.js.map
package/src/hbs.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"hbs.js","sourceRoot":"","sources":["hbs.ts"],"names":[],"mappings":";;;;;;AAAA,gFAAgF;AAChF,sCAAsC;AACtC,qDAAmD;AAGnD,2BAA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GAAG,IAAA,0BAAY,EAAC,UAAU,CAAC,CAAC;AAE3C,SAAS,eAAe,CAAC,UAAsB;IAC7C,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,EAAE,CAAC,EAAE;QAC7B,OAAO,IAAI,CAAC;KACb;IACD,KAAK,CAAC,0BAA0B,EAAE,UAAU,CAAC,EAAE,CAAC,CAAC;IACjD,OAAO;QACL,GAAG,UAAU;QACb,IAAI,EAAE;YACJ,mBAAmB,EAAE;gBACnB,IAAI,EAAE,UAAU;aACjB;SACF;KACF,CAAC;AACJ,CAAC","sourcesContent":["// TODO: I copied this from @embroider/addon-dev, it needs to be its own package\n// (or be in shared-internals or core)\nimport { createFilter } from '@rollup/pluginutils';\nimport type { PluginContext, ResolvedId } from 'rollup';\nimport type { Plugin } from 'vite';\nimport { readFileSync } from 'fs';\nimport { hbsToJS } from '@embroider/core';\nimport assertNever from 'assert-never';\nimport { parse as pathParse } from 'path';\nimport makeDebug from 'debug';\n\nconst debug = makeDebug('embroider:hbs-plugin');\n\nexport function hbs(): Plugin {\n return {\n name: 'rollup-hbs-plugin',\n enforce: 'pre',\n async resolveId(source: string, importer: string | undefined) {\n let resolution = await this.resolve(source, importer, {\n skipSelf: true,\n });\n\n if (!resolution) {\n return maybeSynthesizeComponentJS(this, source, importer);\n } else {\n return maybeRewriteHBS(resolution);\n }\n },\n\n load(id: string) {\n const meta = getMeta(this, id);\n if (!meta) {\n return;\n }\n\n switch (meta.type) {\n case 'template':\n let input = readFileSync(id, 'utf8');\n let code = hbsToJS(input);\n return {\n code,\n };\n case 'template-only-component-js':\n return {\n code: templateOnlyComponent,\n };\n default:\n assertNever(meta);\n }\n },\n };\n}\n\nconst templateOnlyComponent =\n `import templateOnly from '@ember/component/template-only';\\n` + `export default templateOnly();\\n`;\n\ntype Meta =\n | {\n type: 'template';\n }\n | {\n type: 'template-only-component-js';\n };\n\nfunction getMeta(context: PluginContext, id: string): Meta | null {\n const meta = context.getModuleInfo(id)?.meta?.['rollup-hbs-plugin'];\n if (meta) {\n return meta as Meta;\n } else {\n return null;\n }\n}\n\nfunction correspondingTemplate(filename: string): string {\n let { ext } = pathParse(filename);\n return filename.slice(0, filename.length - ext.length) + '.hbs';\n}\n\nasync function maybeSynthesizeComponentJS(context: PluginContext, source: string, importer: string | undefined) {\n debug(`checking for template-only component: %s`, source);\n let templateResolution = await context.resolve(correspondingTemplate(source), importer, {\n skipSelf: true,\n custom: {\n embroider: {\n // we don't want to recurse into the whole embroider compatbility\n // resolver here. It has presumably already steered our request to the\n // correct place. All we want to do is slightly modify the request we\n // were given (changing the extension) and check if that would resolve\n // instead.\n //\n // Currently this guard is only actually exercised in rollup, not in\n // vite, due to https://github.com/vitejs/vite/issues/13852\n enableCustomResolver: false,\n },\n },\n });\n if (!templateResolution) {\n return null;\n }\n debug(`emitting template only component: %s`, templateResolution.id);\n\n // we're trying to resolve a JS module but only the corresponding HBS\n // file exists. Synthesize the template-only component JS.\n return {\n id: templateResolution.id.replace(/\\.hbs$/, '.js'),\n meta: {\n 'rollup-hbs-plugin': {\n type: 'template-only-component-js',\n },\n },\n };\n}\n\nconst hbsFilter = createFilter('**/*.hbs');\n\nfunction maybeRewriteHBS(resolution: ResolvedId) {\n if (!hbsFilter(resolution.id)) {\n return null;\n }\n debug('emitting hbs rewrite: %s', resolution.id);\n return {\n ...resolution,\n meta: {\n 'rollup-hbs-plugin': {\n type: 'template',\n },\n },\n };\n}\n"]}
1
+ {"version":3,"file":"hbs.js","sourceRoot":"","sources":["hbs.ts"],"names":[],"mappings":";;AAcA,kBA0EC;AAxFD,qDAAmD;AAGnD,0CAMyB;AAEzB,MAAM,cAAc,GAAG,IAAI,qBAAc,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;AACzD,MAAM,SAAS,GAAG,IAAA,0BAAY,EAAC,iBAAiB,CAAC,CAAC;AAElD,SAAgB,GAAG;IACjB,OAAO;QACL,IAAI,EAAE,mBAAmB;QACzB,OAAO,EAAE,KAAK;QACd,KA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AI,EAAE,4BAA4B;yBACnC;qBACF;iBACF,CAAC;YACJ,CAAC;QACH,CAAC;QAED,IAAI,CAAC,EAAU;;YACb,IAAI,CAAA,MAAA,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,0CAAE,IAAI,MAAK,4BAA4B,EAAE,CAAC;gBAC7D,OAAO;oBACL,IAAI,EAAE,IAAA,kCAA2B,GAAE;iBACpC,CAAC;YACJ,CAAC;QACH,CAAC;QAED,SAAS,CAAC,IAAY,EAAE,EAAU;YAChC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,EAAE,CAAC;gBACnB,OAAO,IAAI,CAAC;YACd,CAAC;YACD,OAAO,IAAA,cAAO,EAAC,IAAI,CAAC,CAAC;QACvB,CAAC;KACF,CAAC;AACJ,CAAC;AAMD,SAAS,OAAO,CAAC,OAAsB,EAAE,EAAU;;IACjD,MAAM,IAAI,GAAG,MAAA,MAAA,OAAO,CAAC,aAAa,CAAC,EAAE,CAAC,0CAAE,IAAI,0CAAG,mBAAmB,CAAC,CAAC;IACpE,IAAI,IAAI,EAAE,CAAC;QACT,OAAO,IAAY,CAAC;IACtB,CAAC;SAAM,CAAC;QACN,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC","sourcesContent":["import { createFilter } from '@rollup/pluginutils';\nimport type { PluginContext } from 'rollup';\nimport type { Plugin } from 'vite';\nimport {\n hbsToJS,\n ResolverLoader,\n needsSyntheticComponentJS,\n templateOnlyComponentSource,\n syntheticJStoHBS,\n} from '@embroider/core';\n\nconst resolverLoader = new ResolverLoader(process.cwd());\nconst hbsFilter = createFilter('**/*.hbs?([?]*)');\n\nexport function hbs(): Plugin {\n return {\n name: 'rollup-hbs-plugin',\n enforce: 'pre',\n async resolveId(source: string, importer: string | undefined, options) {\n if (options.custom?.depScan) {\n // during depscan we have a corresponding esbuild plugin that is\n // responsible for this stuff instead. We don't want to fight with it.\n return null;\n }\n\n if (options.custom?.embroider?.isExtensionSearch) {\n return null;\n }\n\n let resolution = await this.resolve(source, importer, {\n skipSelf: true,\n });\n\n if (!resolution) {\n let hbsSource = syntheticJStoHBS(source);\n if (hbsSource) {\n resolution = await this.resolve(hbsSource, importer, {\n skipSelf: true,\n custom: {\n embroider: {\n // we don't want to recurse into the whole embroider compatbility\n // resolver here. It has presumably already steered our request to the\n // correct place. All we want to do is slightly modify the request we\n // were given (changing the extension) and check if that would resolve\n // instead.\n //\n // Currently this guard is only actually exercised in rollup, not in\n // vite, due to https://github.com/vitejs/vite/issues/13852\n enableCustomResolver: false,\n isExtensionSearch: true,\n },\n },\n });\n }\n\n if (!resolution) {\n return null;\n }\n }\n\n let syntheticId = needsSyntheticComponentJS(source, resolution.id, resolverLoader.resolver.packageCache);\n if (syntheticId) {\n return {\n id: syntheticId,\n meta: {\n 'rollup-hbs-plugin': {\n type: 'template-only-component-js',\n },\n },\n };\n }\n },\n\n load(id: string) {\n if (getMeta(this, id)?.type === 'template-only-component-js') {\n return {\n code: templateOnlyComponentSource(),\n };\n }\n },\n\n transform(code: string, id: string) {\n if (!hbsFilter(id)) {\n return null;\n }\n return hbsToJS(code);\n },\n };\n}\n\ntype Meta = {\n type: 'template-only-component-js';\n};\n\nfunction getMeta(context: PluginContext, id: string): Meta | null {\n const meta = context.getModuleInfo(id)?.meta?.['rollup-hbs-plugin'];\n if (meta) {\n return meta as Meta;\n } else {\n return null;\n }\n}\n"]}
@@ -1,10 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.optimizeDeps = void 0;
3
+ exports.optimizeDeps = optimizeDeps;
4
+ const esbuild_resolver_1 = require("./esbuild-resolver");
4
5
  function optimizeDeps() {
5
6
  return {
6
7
  exclude: ['@embroider/macros'],
8
+ extensions: ['.hbs', '.gjs', '.gts'],
9
+ esbuildOptions: {
10
+ plugins: [(0, esbuild_resolver_1.esBuildResolver)()],
11
+ },
7
12
  };
8
13
  }
9
- exports.optimizeDeps = optimizeDeps;
10
14
  //# sourceMappingURL=optimize-deps.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"optimize-deps.js","sourceRoot":"","sources":["optimize-deps.ts"],"names":[],"mappings":";;;AAKA,SAAgB,YAAY;IAC1B,OAAO;QACL,OAAO,EAAE,CAAC,mBAAmB,CAAC;KAC/B,CAAC;AACJ,CAAC;AAJD,oCAIC","sourcesContent":["export interface OptimizeDeps {\n exclude?: string[];\n [key: string]: unknown;\n}\n\nexport function optimizeDeps(): OptimizeDeps {\n return {\n exclude: ['@embroider/macros'],\n };\n}\n"]}
1
+ {"version":3,"file":"optimize-deps.js","sourceRoot":"","sources":["optimize-deps.ts"],"names":[],"mappings":";;AAOA,oCAQC;AAfD,yDAAqD;AAOrD,SAAgB,YAAY;IAC1B,OAAO;QACL,OAAO,EAAE,CAAC,mBAAmB,CAAC;QAC9B,UAAU,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC;QACpC,cAAc,EAAE;YACd,OAAO,EAAE,CAAC,IAAA,kCAAe,GAAE,CAAC;SAC7B;KACF,CAAC;AACJ,CAAC","sourcesContent":["import { esBuildResolver } from './esbuild-resolver';\n\nexport interface OptimizeDeps {\n exclude?: string[];\n [key: string]: unknown;\n}\n\nexport function optimizeDeps(): OptimizeDeps {\n return {\n exclude: ['@embroider/macros'],\n extensions: ['.hbs', '.gjs', '.gts'],\n esbuildOptions: {\n plugins: [esBuildResolver()],\n },\n };\n}\n"]}
package/src/request.d.ts CHANGED
@@ -1,14 +1,26 @@
1
- import type { ModuleRequest } from '@embroider/core';
1
+ import type { ModuleRequest, Resolution } from '@embroider/core';
2
+ import type { PluginContext, ResolveIdResult } from 'rollup';
2
3
  export declare const virtualPrefix = "embroider_virtual:";
3
4
  export declare class RollupModuleRequest implements ModuleRequest {
5
+ private context;
4
6
  readonly specifier: string;
5
7
  readonly fromFile: string;
6
8
  readonly meta: Record<string, any> | undefined;
7
- static from(source: string, importer: string | undefined, custom: Record<string, any> | undefined): RollupModuleRequest | undefined;
9
+ readonly isNotFound: boolean;
10
+ readonly resolvedTo: Resolution<ResolveIdResult> | undefined;
11
+ private queryParams;
12
+ private importerQueryParams;
13
+ static from(context: PluginContext, source: string, importer: string | undefined, custom: Record<string, any> | undefined): RollupModuleRequest | undefined;
8
14
  private constructor();
15
+ get debugType(): string;
9
16
  get isVirtual(): boolean;
17
+ private get specifierWithQueryParams();
18
+ private get fromFileWithQueryParams();
10
19
  alias(newSpecifier: string): this;
11
20
  rehome(newFromFile: string): this;
12
21
  virtualize(filename: string): this;
13
22
  withMeta(meta: Record<string, any> | undefined): this;
23
+ notFound(): this;
24
+ defaultResolve(): Promise<Resolution<ResolveIdResult>>;
25
+ resolveTo(resolution: Resolution<ResolveIdResult>): this;
14
26
  }
package/src/request.js CHANGED
@@ -4,7 +4,7 @@ exports.RollupModuleRequest = exports.virtualPrefix = void 0;
4
4
  const core_1 = require("@embroider/core");
5
5
  exports.virtualPrefix = 'embroider_virtual:';
6
6
  class RollupModuleRequest {
7
- static from(source, importer, custom) {
7
+ static from(context, source, importer, custom) {
8
8
  var _a, _b, _c;
9
9
  if (!((_b = (_a = custom === null || custom === void 0 ? void 0 : custom.embroider) === null || _a === void 0 ? void 0 : _a.enableCustomResolver) !== null && _b !== void 0 ? _b : true)) {
10
10
  return;
@@ -19,33 +19,92 @@ class RollupModuleRequest {
19
19
  }
20
20
  // strip query params off the importer
21
21
  let fromFile = (0, core_1.cleanUrl)(nonVirtual);
22
- return new RollupModuleRequest(source, fromFile, (_c = custom === null || custom === void 0 ? void 0 : custom.embroider) === null || _c === void 0 ? void 0 : _c.meta);
22
+ let importerQueryParams = (0, core_1.getUrlQueryParams)(nonVirtual);
23
+ // strip query params off the source but keep track of them
24
+ // we use regexp-based methods over a URL object because the
25
+ // source can be a relative path.
26
+ let cleanSource = (0, core_1.cleanUrl)(source, true);
27
+ let queryParams = (0, core_1.getUrlQueryParams)(source, true);
28
+ return new RollupModuleRequest(context, cleanSource, fromFile, (_c = custom === null || custom === void 0 ? void 0 : custom.embroider) === null || _c === void 0 ? void 0 : _c.meta, false, undefined, queryParams, importerQueryParams);
23
29
  }
24
30
  }
25
- constructor(specifier, fromFile, meta) {
31
+ constructor(context, specifier, fromFile, meta, isNotFound, resolvedTo, queryParams, importerQueryParams) {
32
+ this.context = context;
26
33
  this.specifier = specifier;
27
34
  this.fromFile = fromFile;
28
35
  this.meta = meta;
36
+ this.isNotFound = isNotFound;
37
+ this.resolvedTo = resolvedTo;
38
+ this.queryParams = queryParams;
39
+ this.importerQueryParams = importerQueryParams;
40
+ }
41
+ get debugType() {
42
+ return 'rollup';
29
43
  }
30
44
  get isVirtual() {
31
45
  return this.specifier.startsWith(exports.virtualPrefix);
32
46
  }
47
+ get specifierWithQueryParams() {
48
+ return `${this.specifier}${this.queryParams}`;
49
+ }
50
+ get fromFileWithQueryParams() {
51
+ return `${this.fromFile}${this.importerQueryParams}`;
52
+ }
33
53
  alias(newSpecifier) {
34
- return new RollupModuleRequest(newSpecifier, this.fromFile, this.meta);
54
+ return new RollupModuleRequest(this.context, newSpecifier, this.fromFile, this.meta, false, undefined, this.queryParams, this.importerQueryParams);
35
55
  }
36
56
  rehome(newFromFile) {
37
57
  if (this.fromFile === newFromFile) {
38
58
  return this;
39
59
  }
40
60
  else {
41
- return new RollupModuleRequest(this.specifier, newFromFile, this.meta);
61
+ return new RollupModuleRequest(this.context, this.specifier, newFromFile, this.meta, false, undefined, this.queryParams, this.importerQueryParams);
42
62
  }
43
63
  }
44
64
  virtualize(filename) {
45
- return new RollupModuleRequest(exports.virtualPrefix + filename, this.fromFile, this.meta);
65
+ return new RollupModuleRequest(this.context, exports.virtualPrefix + filename, this.fromFile, this.meta, false, undefined, this.queryParams, this.importerQueryParams);
46
66
  }
47
67
  withMeta(meta) {
48
- return new RollupModuleRequest(this.specifier, this.fromFile, meta);
68
+ return new RollupModuleRequest(this.context, this.specifier, this.fromFile, meta, this.isNotFound, this.resolvedTo, this.queryParams, this.importerQueryParams);
69
+ }
70
+ notFound() {
71
+ return new RollupModuleRequest(this.context, this.specifier, this.fromFile, this.meta, true, undefined, this.queryParams, this.importerQueryParams);
72
+ }
73
+ async defaultResolve() {
74
+ if (this.isVirtual) {
75
+ return {
76
+ type: 'found',
77
+ filename: this.specifier,
78
+ result: { id: this.specifierWithQueryParams, resolvedBy: this.fromFileWithQueryParams },
79
+ isVirtual: this.isVirtual,
80
+ };
81
+ }
82
+ if (this.isNotFound) {
83
+ // TODO: we can make sure this looks correct in rollup & vite output when a
84
+ // user encounters it
85
+ let err = new Error(`module not found ${this.specifierWithQueryParams}`);
86
+ err.code = 'MODULE_NOT_FOUND';
87
+ return { type: 'not_found', err };
88
+ }
89
+ let result = await this.context.resolve(this.specifierWithQueryParams, this.fromFileWithQueryParams, {
90
+ skipSelf: true,
91
+ custom: {
92
+ embroider: {
93
+ enableCustomResolver: false,
94
+ meta: this.meta,
95
+ },
96
+ },
97
+ });
98
+ if (result) {
99
+ let { pathname } = new URL(result.id, 'http://example.com');
100
+ return { type: 'found', filename: pathname, result, isVirtual: this.isVirtual };
101
+ }
102
+ else {
103
+ return { type: 'not_found', err: undefined };
104
+ }
105
+ }
106
+ resolveTo(resolution) {
107
+ return new RollupModuleRequest(this.context, this.specifier, this.fromFile, this.meta, this.isNotFound, resolution, this.queryParams, this.importerQueryParams);
49
108
  }
50
109
  }
51
110
  exports.RollupModuleRequest = RollupModuleRequest;
@@ -1 +1 @@
1
- {"version":3,"file":"request.js","sourceRoot":"","sources":["request.ts"],"names":[],"mappings":";;;AACA,0CAA2C;AAE9B,QAAA,aAAa,GAAG,oBAAoB,CAAC;AAElD,MAAa,mBAAmB;IAC9B,MAAM,CAAC,IAAI,CACT,MAAc,EACd,QAA4B,EAC5B,MAAuC;;QAEvC,IAAI,CAAC,CAAC,MAAA,MAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,SAAS,0CAAE,oBAAoB,mCAAI,IAAI,CAAC,EAAE;YACtD,OAAO;SACR;QAED,IAAI,MAAM,IAAI,QAAQ,IAAI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7F,CAAC;IACD,QAAQ,CAAC,IAAqC;QAC5C,OAAO,IAAI,mBAAmB,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAS,CAAC;IAC9E,CAAC;CACF;AAlDD,kDAkDC","sourcesContent":["import type { ModuleRequest } from '@embroider/core';\nimport { cleanUrl } from '@embroider/core';\n\nexport const virtualPrefix = 'embroider_virtual:';\n\nexport class RollupModuleRequest implements ModuleRequest {\n static from(\n source: string,\n importer: string | undefined,\n custom: Record<string, any> | undefined\n ): RollupModuleRequest | undefined {\n if (!(custom?.embroider?.enableCustomResolver ?? true)) {\n return;\n }\n\n if (source && importer && source[0] !== '\\0') {\n let nonVirtual: string;\n if (importer.startsWith(virtualPrefix)) {\n nonVirtual = importer.slice(virtualPrefix.length);\n } else {\n nonVirtual = importer;\n }\n\n // strip query params off the importer\n let fromFile = cleanUrl(nonVirtual);\n return new RollupModuleRequest(source, fromFile, custom?.embroider?.meta);\n }\n }\n\n private constructor(\n readonly specifier: string,\n readonly fromFile: string,\n readonly meta: Record<string, any> | undefined\n ) {}\n\n get isVirtual(): boolean {\n return this.specifier.startsWith(virtualPrefix);\n }\n\n alias(newSpecifier: string) {\n return new RollupModuleRequest(newSpecifier, this.fromFile, this.meta) as this;\n }\n rehome(newFromFile: string) {\n if (this.fromFile === newFromFile) {\n return this;\n } else {\n return new RollupModuleRequest(this.specifier, newFromFile, this.meta) as this;\n }\n }\n virtualize(filename: string) {\n return new RollupModuleRequest(virtualPrefix + filename, this.fromFile, this.meta) as this;\n }\n withMeta(meta: Record<string, any> | undefined): this {\n return new RollupModuleRequest(this.specifier, this.fromFile, meta) as this;\n }\n}\n"]}
1
+ {"version":3,"file":"request.js","sourceRoot":"","sources":["request.ts"],"names":[],"mappings":";;;AACA,0CAA8D;AAGjD,QAAA,aAAa,GAAG,oBAAoB,CAAC;AAElD,MAAa,mBAAmB;IAC9B,MAAM,CAAC,IAAI,CACT,OAAsB,EACtB,MAAc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AM,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,wBAAwB,EAAE,IAAI,CAAC,uBAAuB,EAAE;YACnG,QAAQ,EAAE,IAAI;YACd,MAAM,EAAE;gBACN,SAAS,EAAE;oBACT,oBAAoB,EAAE,KAAK;oBAC3B,IAAI,EAAE,IAAI,CAAC,IAAI;iBAChB;aACF;SACF,CAAC,CAAC;QACH,IAAI,MAAM,EAAE,CAAC;YACX,IAAI,EAAE,QAAQ,EAAE,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,EAAE,EAAE,oBAAoB,CAAC,CAAC;YAC5D,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,IAAI,CAAC,SAAS,EAAE,CAAC;QAClF,CAAC;aAAM,CAAC;YACN,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,GAAG,EAAE,SAAS,EAAE,CAAC;QAC/C,CAAC;IACH,CAAC;IAED,SAAS,CAAC,UAAuC;QAC/C,OAAO,IAAI,mBAAmB,CAC5B,IAAI,CAAC,OAAO,EACZ,IAAI,CAAC,SAAS,EACd,IAAI,CAAC,QAAQ,EACb,IAAI,CAAC,IAAI,EACT,IAAI,CAAC,UAAU,EACf,UAAU,EACV,IAAI,CAAC,WAAW,EAChB,IAAI,CAAC,mBAAmB,CACjB,CAAC;IACZ,CAAC;CACF;AAjLD,kDAiLC","sourcesContent":["import type { ModuleRequest, Resolution } from '@embroider/core';\nimport { cleanUrl, getUrlQueryParams } from '@embroider/core';\nimport type { PluginContext, ResolveIdResult } from 'rollup';\n\nexport const virtualPrefix = 'embroider_virtual:';\n\nexport class RollupModuleRequest implements ModuleRequest {\n static from(\n context: PluginContext,\n source: string,\n importer: string | undefined,\n custom: Record<string, any> | undefined\n ): RollupModuleRequest | undefined {\n if (!(custom?.embroider?.enableCustomResolver ?? true)) {\n return;\n }\n if (source && importer && source[0] !== '\\0') {\n let nonVirtual: string;\n if (importer.startsWith(virtualPrefix)) {\n nonVirtual = importer.slice(virtualPrefix.length);\n } else {\n nonVirtual = importer;\n }\n\n // strip query params off the importer\n let fromFile = cleanUrl(nonVirtual);\n let importerQueryParams = getUrlQueryParams(nonVirtual);\n\n // strip query params off the source but keep track of them\n // we use regexp-based methods over a URL object because the\n // source can be a relative path.\n let cleanSource = cleanUrl(source, true);\n let queryParams = getUrlQueryParams(source, true);\n\n return new RollupModuleRequest(\n context,\n cleanSource,\n fromFile,\n custom?.embroider?.meta,\n false,\n undefined,\n queryParams,\n importerQueryParams\n );\n }\n }\n\n private constructor(\n private context: PluginContext,\n readonly specifier: string,\n readonly fromFile: string,\n readonly meta: Record<string, any> | undefined,\n readonly isNotFound: boolean,\n readonly resolvedTo: Resolution<ResolveIdResult> | undefined,\n private queryParams: string,\n private importerQueryParams: string\n ) {}\n\n get debugType() {\n return 'rollup';\n }\n\n get isVirtual(): boolean {\n return this.specifier.startsWith(virtualPrefix);\n }\n\n private get specifierWithQueryParams(): string {\n return `${this.specifier}${this.queryParams}`;\n }\n\n private get fromFileWithQueryParams(): string {\n return `${this.fromFile}${this.importerQueryParams}`;\n }\n\n alias(newSpecifier: string) {\n return new RollupModuleRequest(\n this.context,\n newSpecifier,\n this.fromFile,\n this.meta,\n false,\n undefined,\n this.queryParams,\n this.importerQueryParams\n ) as this;\n }\n rehome(newFromFile: string) {\n if (this.fromFile === newFromFile) {\n return this;\n } else {\n return new RollupModuleRequest(\n this.context,\n this.specifier,\n newFromFile,\n this.meta,\n false,\n undefined,\n this.queryParams,\n this.importerQueryParams\n ) as this;\n }\n }\n virtualize(filename: string) {\n return new RollupModuleRequest(\n this.context,\n virtualPrefix + filename,\n this.fromFile,\n this.meta,\n false,\n undefined,\n this.queryParams,\n this.importerQueryParams\n ) as this;\n }\n withMeta(meta: Record<string, any> | undefined): this {\n return new RollupModuleRequest(\n this.context,\n this.specifier,\n this.fromFile,\n meta,\n this.isNotFound,\n this.resolvedTo,\n this.queryParams,\n this.importerQueryParams\n ) as this;\n }\n notFound(): this {\n return new RollupModuleRequest(\n this.context,\n this.specifier,\n this.fromFile,\n this.meta,\n true,\n undefined,\n this.queryParams,\n this.importerQueryParams\n ) as this;\n }\n async defaultResolve(): Promise<Resolution<ResolveIdResult>> {\n if (this.isVirtual) {\n return {\n type: 'found',\n filename: this.specifier,\n result: { id: this.specifierWithQueryParams, resolvedBy: this.fromFileWithQueryParams },\n isVirtual: this.isVirtual,\n };\n }\n if (this.isNotFound) {\n // TODO: we can make sure this looks correct in rollup & vite output when a\n // user encounters it\n let err = new Error(`module not found ${this.specifierWithQueryParams}`);\n (err as any).code = 'MODULE_NOT_FOUND';\n return { type: 'not_found', err };\n }\n let result = await this.context.resolve(this.specifierWithQueryParams, this.fromFileWithQueryParams, {\n skipSelf: true,\n custom: {\n embroider: {\n enableCustomResolver: false,\n meta: this.meta,\n },\n },\n });\n if (result) {\n let { pathname } = new URL(result.id, 'http://example.com');\n return { type: 'found', filename: pathname, result, isVirtual: this.isVirtual };\n } else {\n return { type: 'not_found', err: undefined };\n }\n }\n\n resolveTo(resolution: Resolution<ResolveIdResult>): this {\n return new RollupModuleRequest(\n this.context,\n this.specifier,\n this.fromFile,\n this.meta,\n this.isNotFound,\n resolution,\n this.queryParams,\n this.importerQueryParams\n ) as this;\n }\n}\n"]}
package/src/resolver.js CHANGED
@@ -3,27 +3,52 @@ 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.resolver = void 0;
7
- const path_1 = require("path");
6
+ exports.resolver = resolver;
8
7
  const core_1 = require("@embroider/core");
9
- const fs_extra_1 = require("fs-extra");
10
8
  const request_1 = require("./request");
11
9
  const assert_never_1 = __importDefault(require("assert-never"));
10
+ const debug_1 = __importDefault(require("debug"));
11
+ const path_1 = require("path");
12
+ const esbuild_request_1 = require("./esbuild-request");
13
+ const debug = (0, debug_1.default)('embroider:vite');
12
14
  function resolver() {
13
- let resolverOptions = (0, fs_extra_1.readJSONSync)((0, path_1.join)((0, core_1.locateEmbroiderWorkingDir)(process.cwd()), 'resolver.json'));
14
- let resolver = new core_1.Resolver(resolverOptions);
15
+ let resolverLoader = new core_1.ResolverLoader(process.cwd());
16
+ let server;
17
+ let virtualDeps = new Map();
15
18
  return {
16
19
  name: 'embroider-resolver',
17
20
  enforce: 'pre',
21
+ configureServer(s) {
22
+ server = s;
23
+ server.watcher.on('all', (_eventName, path) => {
24
+ for (let [id, watches] of virtualDeps) {
25
+ for (let watch of watches) {
26
+ if (path.startsWith(watch)) {
27
+ debug('Invalidate %s because %s', id, path);
28
+ server.moduleGraph.onFileChange(id);
29
+ let m = server.moduleGraph.getModuleById(id);
30
+ if (m) {
31
+ server.reloadModule(m);
32
+ }
33
+ }
34
+ }
35
+ }
36
+ });
37
+ },
18
38
  async resolveId(source, importer, options) {
19
- let request = request_1.RollupModuleRequest.from(source, importer, options.custom);
39
+ var _a;
40
+ if ((_a = options.custom) === null || _a === void 0 ? void 0 : _a.depScan) {
41
+ return await observeDepScan(this, source, importer, options);
42
+ }
43
+ let request = request_1.RollupModuleRequest.from(this, source, importer, options.custom);
20
44
  if (!request) {
21
45
  // fallthrough to other rollup plugins
22
46
  return null;
23
47
  }
24
- let resolution = await resolver.resolve(request, defaultResolve(this));
48
+ let resolution = await resolverLoader.resolver.resolve(request);
25
49
  switch (resolution.type) {
26
50
  case 'found':
51
+ case 'ignored':
27
52
  return resolution.result;
28
53
  case 'not_found':
29
54
  return null;
@@ -33,34 +58,45 @@ function resolver() {
33
58
  },
34
59
  load(id) {
35
60
  if (id.startsWith(request_1.virtualPrefix)) {
36
- return (0, core_1.virtualContent)(id.slice(request_1.virtualPrefix.length), resolver);
61
+ let { pathname } = new URL(id, 'http://example.com');
62
+ let { src, watches } = (0, core_1.virtualContent)(pathname.slice(request_1.virtualPrefix.length + 1), resolverLoader.resolver);
63
+ virtualDeps.set(id, watches);
64
+ server === null || server === void 0 ? void 0 : server.watcher.add(watches);
65
+ return src;
37
66
  }
38
67
  },
68
+ buildEnd() {
69
+ this.emitFile({
70
+ type: 'asset',
71
+ fileName: '@embroider/core/vendor.js',
72
+ source: (0, core_1.virtualContent)((0, path_1.resolve)(resolverLoader.resolver.options.engines[0].root, '-embroider-vendor.js'), resolverLoader.resolver).src,
73
+ });
74
+ this.emitFile({
75
+ type: 'asset',
76
+ fileName: '@embroider/core/test-support.js',
77
+ source: (0, core_1.virtualContent)((0, path_1.resolve)(resolverLoader.resolver.options.engines[0].root, '-embroider-test-support.js'), resolverLoader.resolver).src,
78
+ });
79
+ },
39
80
  };
40
81
  }
41
- exports.resolver = resolver;
42
- function defaultResolve(context) {
43
- return async (request) => {
44
- if (request.isVirtual) {
45
- return {
46
- type: 'found',
47
- result: { id: request.specifier, resolvedBy: request.fromFile },
48
- };
49
- }
50
- let result = await context.resolve(request.specifier, request.fromFile, {
51
- skipSelf: true,
52
- custom: {
53
- embroider: {
54
- meta: request.meta,
55
- },
56
- },
57
- });
58
- if (result) {
59
- return { type: 'found', result };
60
- }
61
- else {
62
- return { type: 'not_found', err: undefined };
63
- }
64
- };
82
+ // During depscan, we have a wildly different job than during normal
83
+ // usage. Embroider's esbuild resolver plugin replaces this rollup
84
+ // resolver plugin for actually doing resolving, so we don't do any of
85
+ // that. But we are still well-positioned to observe what vite's rollup
86
+ // resolver plugin is doing, and that is important because vite's
87
+ // esbuild depscan plugin will always obscure the results before
88
+ // embroider's esbuild resolver plugin can see them. It obscures the
89
+ // results by marking *both* "not found" and "this is a third-party
90
+ // package" as "external: true". We really care about the difference
91
+ // between the two, since we have fallback behaviors that should apply
92
+ // to "not found" that should not apply to successfully discovered
93
+ // third-party packages.
94
+ async function observeDepScan(context, source, importer, options) {
95
+ let result = await context.resolve(source, importer, {
96
+ ...options,
97
+ skipSelf: true,
98
+ });
99
+ (0, esbuild_request_1.writeStatus)(source, result ? 'found' : 'not_found');
100
+ return result;
65
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AAC;KACF,CAAC;AACJ,CAAC;AA7BD,4BA6BC;AAED,SAAS,cAAc,CAAC,OAAsB;IAC5C,OAAO,KAAK,EAAE,OAA4B,EAAE,EAAE;QAC5C,IAAI,OAAO,CAAC,SAAS,EAAE;YACrB,OAAO;gBACL,IAAI,EAAE,OAAO;gBACb,MAAM,EAAE,EAAE,EAAE,EAAE,OAAO,CAAC,SAAS,EAAE,UAAU,EAAE,OAAO,CAAC,QAAQ,EAAE;aAChE,CAAC;SACH;QACD,IAAI,MAAM,GAAG,MAAM,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,SAAS,EAAE,OAAO,CAAC,QAAQ,EAAE;YACtE,QAAQ,EAAE,IAAI;YACd,MAAM,EAAE;gBACN,SAAS,EAAE;oBACT,IAAI,EAAE,OAAO,CAAC,IAAI;iBACnB;aACF;SACF,CAAC,CAAC;QACH,IAAI,MAAM,EAAE;YACV,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC;SAClC;aAAM;YACL,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,GAAG,EAAE,SAAS,EAAE,CAAC;SAC9C;IACH,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import type { PluginContext, ResolveIdResult } from 'rollup';\nimport type { Plugin } from 'vite';\nimport { join } from 'path';\nimport type { Resolution, ResolverFunction, ResolverOptions } from '@embroider/core';\nimport { Resolver, locateEmbroiderWorkingDir, virtualContent } from '@embroider/core';\nimport { readJSONSync } from 'fs-extra';\nimport { RollupModuleRequest, virtualPrefix } from './request';\nimport assertNever from 'assert-never';\n\nexport function resolver(): Plugin {\n let resolverOptions: ResolverOptions = readJSONSync(join(locateEmbroiderWorkingDir(process.cwd()), 'resolver.json'));\n let resolver = new Resolver(resolverOptions);\n\n return {\n name: 'embroider-resolver',\n enforce: 'pre',\n async resolveId(source, importer, options) {\n let request = RollupModuleRequest.from(source, importer, options.custom);\n if (!request) {\n // fallthrough to other rollup plugins\n return null;\n }\n let resolution = await resolver.resolve(request, defaultResolve(this));\n switch (resolution.type) {\n case 'found':\n return resolution.result;\n case 'not_found':\n return null;\n default:\n throw assertNever(resolution);\n }\n },\n load(id) {\n if (id.startsWith(virtualPrefix)) {\n return virtualContent(id.slice(virtualPrefix.length), resolver);\n }\n },\n };\n}\n\nfunction defaultResolve(context: PluginContext): ResolverFunction<RollupModuleRequest, Resolution<ResolveIdResult>> {\n return async (request: RollupModuleRequest) => {\n if (request.isVirtual) {\n return {\n type: 'found',\n result: { id: request.specifier, resolvedBy: request.fromFile },\n };\n }\n let result = await context.resolve(request.specifier, request.fromFile, {\n skipSelf: true,\n custom: {\n embroider: {\n meta: request.meta,\n },\n },\n });\n if (result) {\n return { type: 'found', result };\n } else {\n return { type: 'not_found', err: undefined };\n }\n };\n}\n"]}
1
+ {"version":3,"file":"resolver.js","sourceRoot":"","sources":["resolver.ts"],"names":[],"mappings":";;;;;AAWA,4BA4EC;AAtFD,0CAAiE;AACjE,uCAA+D;AAC/D,gEAAuC;AACvC,kDAA8B;AAC9B,+BAA+B;AAC/B,uDAAgD;AAGhD,MAAM,KAAK,GAAG,IAAA,eAAS,EAAC,gBAAgB,CAAC,CAAC;AAE1C,SAAgB,QAAQ;IACtB,IAAI,cAAc,GAAG,IAAI,qBAAc,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;IACvD,IAAI,MAAqB,CAAC;IAC1B,IAAI,WAAW,GAA0B,IAAI,GAAG,EAAE,CAAC;IAEnD,OAAO;QACL,IAAI,EAAE,oBAAoB;QAC1B,OAAO,EAAE,KAAK;QAEd,eAAe,CAAC,CAAC;YACf,MAAM,GAAG,CAAC,CAAC;YACX,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,UAAU,EAAE,IAAI,EAAE,EAAE;gBAC5C,KAAK,IAAI,CAAC,EAAE,EAAE,OAAO,CAAC,IAAI,WAAW,EAAE,CAAC;oBACtC,KAAK,IAAI,KAAK,IAAI,OAAO,EAAE,CAAC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;AACpE,mEAAmE;AACnE,oEAAoE;AACpE,sEAAsE;AACtE,kEAAkE;AAClE,wBAAwB;AACxB,KAAK,UAAU,cAAc,CAAC,OAAsB,EAAE,MAAc,EAAE,QAA4B,EAAE,OAAY;IAC9G,IAAI,MAAM,GAAG,MAAM,OAAO,CAAC,OAAO,CAAC,MAAM,EAAE,QAAQ,EAAE;QACnD,GAAG,OAAO;QACV,QAAQ,EAAE,IAAI;KACf,CAAC,CAAC;IACH,IAAA,6BAAW,EAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC;IACpD,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import type { Plugin, ViteDevServer } from 'vite';\nimport { virtualContent, ResolverLoader } from '@embroider/core';\nimport { RollupModuleRequest, virtualPrefix } from './request';\nimport assertNever from 'assert-never';\nimport makeDebug from 'debug';\nimport { resolve } from 'path';\nimport { writeStatus } from './esbuild-request';\nimport type { PluginContext } from 'rollup';\n\nconst debug = makeDebug('embroider:vite');\n\nexport function resolver(): Plugin {\n let resolverLoader = new ResolverLoader(process.cwd());\n let server: ViteDevServer;\n let virtualDeps: Map<string, string[]> = new Map();\n\n return {\n name: 'embroider-resolver',\n enforce: 'pre',\n\n configureServer(s) {\n server = s;\n server.watcher.on('all', (_eventName, path) => {\n for (let [id, watches] of virtualDeps) {\n for (let watch of watches) {\n if (path.startsWith(watch)) {\n debug('Invalidate %s because %s', id, path);\n server.moduleGraph.onFileChange(id);\n let m = server.moduleGraph.getModuleById(id);\n if (m) {\n server.reloadModule(m);\n }\n }\n }\n }\n });\n },\n\n async resolveId(source, importer, options) {\n if (options.custom?.depScan) {\n return await observeDepScan(this, source, importer, options);\n }\n\n let request = RollupModuleRequest.from(this, source, importer, options.custom);\n if (!request) {\n // fallthrough to other rollup plugins\n return null;\n }\n let resolution = await resolverLoader.resolver.resolve(request);\n switch (resolution.type) {\n case 'found':\n case 'ignored':\n return resolution.result;\n case 'not_found':\n return null;\n default:\n throw assertNever(resolution);\n }\n },\n load(id) {\n if (id.startsWith(virtualPrefix)) {\n let { pathname } = new URL(id, 'http://example.com');\n let { src, watches } = virtualContent(pathname.slice(virtualPrefix.length + 1), resolverLoader.resolver);\n virtualDeps.set(id, watches);\n server?.watcher.add(watches);\n return src;\n }\n },\n buildEnd() {\n this.emitFile({\n type: 'asset',\n fileName: '@embroider/core/vendor.js',\n source: virtualContent(\n resolve(resolverLoader.resolver.options.engines[0].root, '-embroider-vendor.js'),\n resolverLoader.resolver\n ).src,\n });\n this.emitFile({\n type: 'asset',\n fileName: '@embroider/core/test-support.js',\n source: virtualContent(\n resolve(resolverLoader.resolver.options.engines[0].root, '-embroider-test-support.js'),\n resolverLoader.resolver\n ).src,\n });\n },\n };\n}\n\n// During depscan, we have a wildly different job than during normal\n// usage. Embroider's esbuild resolver plugin replaces this rollup\n// resolver plugin for actually doing resolving, so we don't do any of\n// that. But we are still well-positioned to observe what vite's rollup\n// resolver plugin is doing, and that is important because vite's\n// esbuild depscan plugin will always obscure the results before\n// embroider's esbuild resolver plugin can see them. It obscures the\n// results by marking *both* \"not found\" and \"this is a third-party\n// package\" as \"external: true\". We really care about the difference\n// between the two, since we have fallback behaviors that should apply\n// to \"not found\" that should not apply to successfully discovered\n// third-party packages.\nasync function observeDepScan(context: PluginContext, source: string, importer: string | undefined, options: any) {\n let result = await context.resolve(source, importer, {\n ...options,\n skipSelf: true,\n });\n writeStatus(source, result ? 'found' : 'not_found');\n return result;\n}\n"]}
package/src/scripts.js CHANGED
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.scripts = void 0;
26
+ exports.scripts = scripts;
27
27
  const jsdom_1 = require("jsdom");
28
28
  const fs_extra_1 = require("fs-extra");
29
29
  const path_1 = require("path");
@@ -65,17 +65,21 @@ function scripts(params) {
65
65
  },
66
66
  };
67
67
  }
68
- exports.scripts = scripts;
69
68
  class ScriptOptimizer {
70
69
  constructor(rootDir) {
71
70
  this.rootDir = rootDir;
72
71
  this.emitted = new Map();
73
72
  }
74
73
  async optimizedScript(script) {
74
+ let fullName = (0, path_1.resolve)(this.rootDir, script.slice(1));
75
+ if (!(0, fs_extra_1.existsSync)(fullName)) {
76
+ // in prod builds, test-support.js isn't going to exist (for example)
77
+ return [];
78
+ }
75
79
  // loading these lazily here so they never load in non-production builds.
76
80
  // The node cache will ensures we only load them once.
77
81
  const [Terser, srcURL] = await Promise.all([Promise.resolve().then(() => __importStar(require('terser'))), Promise.resolve().then(() => __importStar(require('source-map-url')))]);
78
- let inCode = (0, fs_extra_1.readFileSync)((0, path_1.resolve)(this.rootDir, script.slice(1)), 'utf8');
82
+ let inCode = (0, fs_extra_1.readFileSync)(fullName, 'utf8');
79
83
  let terserOpts = {};
80
84
  let fileRelativeSourceMapURL;
81
85
  let appRelativeSourceMapURL;