@embroider/vite 0.2.1 → 0.2.2-unstable.aaeb674

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.
@@ -0,0 +1,150 @@
1
+ import { transform } from '@babel/core';
2
+ import core from '@embroider/core';
3
+ const { ResolverLoader, virtualContent, needsSyntheticComponentJS, isInComponents } = core;
4
+ import fs from 'fs-extra';
5
+ const { readFileSync } = fs;
6
+ import { EsBuildModuleRequest } from './esbuild-request.js';
7
+ import { assertNever } from 'assert-never';
8
+ import { hbsToJS } from '@embroider/core';
9
+ import { Preprocessor } from 'content-tag';
10
+ import { extname } from 'path';
11
+ const templateOnlyComponent = `import templateOnly from '@ember/component/template-only';\n` + `export default templateOnly();\n`;
12
+ export function esBuildResolver() {
13
+ let resolverLoader = new ResolverLoader(process.cwd());
14
+ let preprocessor = new Preprocessor();
15
+ function transformAndAssert(src, filename) {
16
+ const result = transform(src, { filename });
17
+ if (!result || result.code == null) {
18
+ throw new Error(`Failed to load file ${filename} in esbuild-hbs-loader`);
19
+ }
20
+ return result.code;
21
+ }
22
+ function onLoad({ path, namespace }) {
23
+ let src;
24
+ if (namespace === 'embroider-template-only-component') {
25
+ src = templateOnlyComponent;
26
+ }
27
+ else if (namespace === 'embroider-virtual') {
28
+ src = virtualContent(path, resolverLoader.resolver).src;
29
+ }
30
+ else {
31
+ src = readFileSync(path, 'utf8');
32
+ }
33
+ if (path.endsWith('.hbs')) {
34
+ src = hbsToJS(src);
35
+ }
36
+ else if (['.gjs', '.gts'].some(ext => path.endsWith(ext))) {
37
+ src = preprocessor.process(src, { filename: path });
38
+ }
39
+ if (['.hbs', '.gjs', '.gts', '.js', '.ts'].some(ext => path.endsWith(ext))) {
40
+ src = transformAndAssert(src, path);
41
+ }
42
+ return { contents: src };
43
+ }
44
+ return {
45
+ name: 'embroider-esbuild-resolver',
46
+ setup(build) {
47
+ const phase = detectPhase(build);
48
+ // Embroider Resolver
49
+ build.onResolve({ filter: /./ }, async ({ path, importer, pluginData, kind }) => {
50
+ let request = EsBuildModuleRequest.from(resolverLoader.resolver.packageCache, phase, build, kind, path, importer, pluginData);
51
+ if (!request) {
52
+ return null;
53
+ }
54
+ let resolution = await resolverLoader.resolver.resolve(request);
55
+ switch (resolution.type) {
56
+ case 'found':
57
+ case 'ignored':
58
+ return resolution.result;
59
+ case 'not_found':
60
+ return resolution.err;
61
+ default:
62
+ throw assertNever(resolution);
63
+ }
64
+ });
65
+ // template-only-component synthesis
66
+ build.onResolve({ filter: /./ }, async ({ path, importer, namespace, resolveDir, pluginData, kind }) => {
67
+ if (pluginData === null || pluginData === void 0 ? void 0 : pluginData.embroiderHBSResolving) {
68
+ // reentrance
69
+ return null;
70
+ }
71
+ let result = await build.resolve(path, {
72
+ namespace,
73
+ resolveDir,
74
+ importer,
75
+ kind,
76
+ // avoid reentrance
77
+ pluginData: { ...pluginData, embroiderHBSResolving: true },
78
+ });
79
+ if (result.errors.length === 0 && !result.external) {
80
+ let syntheticPath = needsSyntheticComponentJS(path, result.path);
81
+ if (syntheticPath && isInComponents(result.path, resolverLoader.resolver.packageCache)) {
82
+ return { path: syntheticPath, namespace: 'embroider-template-only-component' };
83
+ }
84
+ }
85
+ return result;
86
+ });
87
+ if (phase === 'bundling') {
88
+ // during bundling phase, we need to provide our own extension
89
+ // searching. We do it here in its own resolve plugin so that it's
90
+ // sitting beneath both embroider resolver and template-only-component
91
+ // synthesizer, since both expect the ambient system to have extension
92
+ // search.
93
+ build.onResolve({ filter: /./ }, async ({ path, importer, namespace, resolveDir, pluginData, kind }) => {
94
+ if (pluginData === null || pluginData === void 0 ? void 0 : pluginData.embroiderExtensionResolving) {
95
+ // reentrance
96
+ return null;
97
+ }
98
+ let firstResult;
99
+ for (let requestName of extensionSearch(path, resolverLoader.resolver.options.resolvableExtensions)) {
100
+ let result = await build.resolve(requestName, {
101
+ namespace,
102
+ resolveDir,
103
+ importer,
104
+ kind,
105
+ // avoid reentrance
106
+ pluginData: { ...pluginData, embroiderExtensionResolving: true },
107
+ });
108
+ if (result.errors.length > 0) {
109
+ // if extension search fails, we want to let the first failure be the
110
+ // one that propagates, so that the error message makes sense.
111
+ firstResult = result;
112
+ }
113
+ else {
114
+ return result;
115
+ }
116
+ }
117
+ return firstResult;
118
+ });
119
+ }
120
+ // we need to handle everything from one of our three special namespaces:
121
+ build.onLoad({ namespace: 'embroider-template-only-component', filter: /./ }, onLoad);
122
+ build.onLoad({ namespace: 'embroider-virtual', filter: /./ }, onLoad);
123
+ build.onLoad({ namespace: 'embroider-template-tag', filter: /./ }, onLoad);
124
+ // we need to handle all hbs
125
+ build.onLoad({ filter: /\.hbs$/ }, onLoad);
126
+ // we need to handle all GJS (to preprocess) and JS (to run macros)
127
+ build.onLoad({ filter: /\.g?[jt]s$/ }, onLoad);
128
+ },
129
+ };
130
+ }
131
+ function detectPhase(build) {
132
+ var _a;
133
+ let plugins = ((_a = build.initialOptions.plugins) !== null && _a !== void 0 ? _a : []).map(p => p.name);
134
+ if (plugins.includes('vite:dep-pre-bundle')) {
135
+ return 'bundling';
136
+ }
137
+ else {
138
+ return 'other';
139
+ }
140
+ }
141
+ function* extensionSearch(specifier, extensions) {
142
+ yield specifier;
143
+ // when there's no explicit extension, we may do extension search
144
+ if (extname(specifier) === '') {
145
+ for (let ext of extensions) {
146
+ yield specifier + ext;
147
+ }
148
+ }
149
+ }
150
+ //# sourceMappingURL=esbuild-resolver.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"esbuild-resolver.js","sourceRoot":"","sources":["esbuild-resolver.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,IAAI,MAAM,iBAAiB,CAAC;AACnC,MAAM,EAAE,cAAc,EAAE,cAAc,EAAE,yBAAyB,EAAE,cAAc,EAAE,GAAG,IAAI,CAAC;AAC3F,OAAO,EAAE,MAAM,UAAU,CAAC;AAC1B,MAAM,EAAE,YAAY,EAAE,GAAG,EAAE,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AAmB,EAAE,MAAM,EAAE,GAAG,EAAE,EAAE,MAAM,CAAC,CAAC;YACtE,KAAK,CAAC,MAAM,CAAC,EAAE,SAAS,EAAE,wBAAwB,EAAE,MAAM,EAAE,GAAG,EAAE,EAAE,MAAM,CAAC,CAAC;YAE3E,4BAA4B;YAC5B,KAAK,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,MAAM,CAAC,CAAC;YAE3C,mEAAmE;YACnE,KAAK,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,YAAY,EAAE,EAAE,MAAM,CAAC,CAAC;QACjD,CAAC;KACF,CAAC;AACJ,CAAC;AAED,SAAS,WAAW,CAAC,KAAkB;;IACrC,IAAI,OAAO,GAAG,CAAC,MAAA,KAAK,CAAC,cAAc,CAAC,OAAO,mCAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IACpE,IAAI,OAAO,CAAC,QAAQ,CAAC,qBAAqB,CAAC,EAAE,CAAC;QAC5C,OAAO,UAAU,CAAC;IACpB,CAAC;SAAM,CAAC;QACN,OAAO,OAAO,CAAC;IACjB,CAAC;AACH,CAAC;AAED,QAAQ,CAAC,CAAC,eAAe,CAAC,SAAiB,EAAE,UAAoB;IAC/D,MAAM,SAAS,CAAC;IAChB,iEAAiE;IACjE,IAAI,OAAO,CAAC,SAAS,CAAC,KAAK,EAAE,EAAE,CAAC;QAC9B,KAAK,IAAI,GAAG,IAAI,UAAU,EAAE,CAAC;YAC3B,MAAM,SAAS,GAAG,GAAG,CAAC;QACxB,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["import type { Plugin as EsBuildPlugin, OnLoadResult, PluginBuild, ResolveResult } from 'esbuild';\nimport { transform } from '@babel/core';\nimport core from '@embroider/core';\nconst { ResolverLoader, virtualContent, needsSyntheticComponentJS, isInComponents } = core;\nimport fs from 'fs-extra';\nconst { readFileSync } = fs;\nimport { EsBuildModuleRequest } from './esbuild-request.js';\nimport { assertNever } from 'assert-never';\nimport { hbsToJS } from '@embroider/core';\nimport { Preprocessor } from 'content-tag';\nimport { extname } from 'path';\n\nconst templateOnlyComponent =\n `import templateOnly from '@ember/component/template-only';\\n` + `export default templateOnly();\\n`;\n\nexport function esBuildResolver(): EsBuildPlugin {\n let resolverLoader = new ResolverLoader(process.cwd());\n let preprocessor = new Preprocessor();\n\n function transformAndAssert(src: string, filename: string): string {\n const result = transform(src, { filename });\n if (!result || result.code == null) {\n throw new Error(`Failed to load file ${filename} in esbuild-hbs-loader`);\n }\n return result.code!;\n }\n\n function onLoad({ path, namespace }: { path: string; namespace: string }): OnLoadResult {\n let src: string;\n if (namespace === 'embroider-template-only-component') {\n src = templateOnlyComponent;\n } else if (namespace === 'embroider-virtual') {\n src = virtualContent(path, resolverLoader.resolver).src;\n } else {\n src = readFileSync(path, 'utf8');\n }\n if (path.endsWith('.hbs')) {\n src = hbsToJS(src);\n } else if (['.gjs', '.gts'].some(ext => path.endsWith(ext))) {\n src = preprocessor.process(src, { filename: path });\n }\n if (['.hbs', '.gjs', '.gts', '.js', '.ts'].some(ext => path.endsWith(ext))) {\n src = transformAndAssert(src, path);\n }\n return { contents: src };\n }\n\n return {\n name: 'embroider-esbuild-resolver',\n setup(build) {\n const phase = detectPhase(build);\n\n // Embroider Resolver\n build.onResolve({ filter: /./ }, async ({ path, importer, pluginData, kind }) => {\n let request = EsBuildModuleRequest.from(\n resolverLoader.resolver.packageCache,\n phase,\n build,\n kind,\n path,\n importer,\n pluginData\n );\n if (!request) {\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 resolution.err;\n default:\n throw assertNever(resolution);\n }\n });\n\n // template-only-component synthesis\n build.onResolve({ filter: /./ }, async ({ path, importer, namespace, resolveDir, pluginData, kind }) => {\n if (pluginData?.embroiderHBSResolving) {\n // reentrance\n return null;\n }\n\n let result = await build.resolve(path, {\n namespace,\n resolveDir,\n importer,\n kind,\n // avoid reentrance\n pluginData: { ...pluginData, embroiderHBSResolving: true },\n });\n\n if (result.errors.length === 0 && !result.external) {\n let syntheticPath = needsSyntheticComponentJS(path, result.path);\n if (syntheticPath && isInComponents(result.path, resolverLoader.resolver.packageCache)) {\n return { path: syntheticPath, namespace: 'embroider-template-only-component' };\n }\n }\n\n return result;\n });\n\n if (phase === 'bundling') {\n // during bundling phase, we need to provide our own extension\n // searching. We do it here in its own resolve plugin so that it's\n // sitting beneath both embroider resolver and template-only-component\n // synthesizer, since both expect the ambient system to have extension\n // search.\n build.onResolve({ filter: /./ }, async ({ path, importer, namespace, resolveDir, pluginData, kind }) => {\n if (pluginData?.embroiderExtensionResolving) {\n // reentrance\n return null;\n }\n\n let firstResult: ResolveResult | undefined;\n\n for (let requestName of extensionSearch(path, resolverLoader.resolver.options.resolvableExtensions)) {\n let result = await build.resolve(requestName, {\n namespace,\n resolveDir,\n importer,\n kind,\n // avoid reentrance\n pluginData: { ...pluginData, embroiderExtensionResolving: true },\n });\n\n if (result.errors.length > 0) {\n // if extension search fails, we want to let the first failure be the\n // one that propagates, so that the error message makes sense.\n firstResult = result;\n } else {\n return result;\n }\n }\n\n return firstResult;\n });\n }\n\n // we need to handle everything from one of our three special namespaces:\n build.onLoad({ namespace: 'embroider-template-only-component', filter: /./ }, onLoad);\n build.onLoad({ namespace: 'embroider-virtual', filter: /./ }, onLoad);\n build.onLoad({ namespace: 'embroider-template-tag', filter: /./ }, onLoad);\n\n // we need to handle all hbs\n build.onLoad({ filter: /\\.hbs$/ }, onLoad);\n\n // we need to handle all GJS (to preprocess) and JS (to run macros)\n build.onLoad({ filter: /\\.g?[jt]s$/ }, onLoad);\n },\n };\n}\n\nfunction detectPhase(build: PluginBuild): 'bundling' | 'other' {\n let plugins = (build.initialOptions.plugins ?? []).map(p => p.name);\n if (plugins.includes('vite:dep-pre-bundle')) {\n return 'bundling';\n } else {\n return 'other';\n }\n}\n\nfunction* extensionSearch(specifier: string, extensions: string[]): Generator<string> {\n yield specifier;\n // when there's no explicit extension, we may do extension search\n if (extname(specifier) === '') {\n for (let ext of extensions) {\n yield specifier + ext;\n }\n }\n}\n"]}
package/src/hbs.js CHANGED
@@ -1,56 +1,81 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.hbs = hbs;
7
- // TODO: I copied this from @embroider/addon-dev, it needs to be its own package
8
- // (or be in shared-internals or core)
9
- const pluginutils_1 = require("@rollup/pluginutils");
10
- const fs_1 = require("fs");
11
- 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');
16
- function hbs() {
1
+ import { createFilter } from '@rollup/pluginutils';
2
+ import { hbsToJS, ResolverLoader, needsSyntheticComponentJS, isInComponents, templateOnlyComponentSource, syntheticJStoHBS, } from '@embroider/core';
3
+ const resolverLoader = new ResolverLoader(process.cwd());
4
+ const hbsFilter = createFilter('**/*.hbs?([?]*)');
5
+ export function hbs() {
17
6
  return {
18
7
  name: 'rollup-hbs-plugin',
19
8
  enforce: 'pre',
20
- async resolveId(source, importer) {
9
+ async resolveId(source, importer, options) {
10
+ var _a, _b, _c;
11
+ if ((_a = options.custom) === null || _a === void 0 ? void 0 : _a.depScan) {
12
+ // during depscan we have a corresponding esbuild plugin that is
13
+ // responsible for this stuff instead. We don't want to fight with it.
14
+ return null;
15
+ }
16
+ if ((_c = (_b = options.custom) === null || _b === void 0 ? void 0 : _b.embroider) === null || _c === void 0 ? void 0 : _c.isExtensionSearch) {
17
+ return null;
18
+ }
21
19
  let resolution = await this.resolve(source, importer, {
22
20
  skipSelf: true,
23
21
  });
24
22
  if (!resolution) {
25
- return maybeSynthesizeComponentJS(this, source, importer);
23
+ // vite already has extension search fallback for extensionless imports.
24
+ // This is different, it covers an explicit .js import fallback to the
25
+ // corresponding hbs.
26
+ let hbsSource = 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 = needsSyntheticComponentJS(source, resolution.id);
51
+ if (syntheticId && isInComponents(resolution.id, resolverLoader.resolver.packageCache)) {
52
+ return {
53
+ id: syntheticId,
54
+ meta: {
55
+ 'rollup-hbs-plugin': {
56
+ type: 'template-only-component-js',
57
+ },
58
+ },
59
+ };
29
60
  }
61
+ return resolution;
30
62
  },
31
63
  load(id) {
32
- const meta = getMeta(this, id);
33
- if (!meta) {
34
- return;
64
+ var _a;
65
+ if (((_a = getMeta(this, id)) === null || _a === void 0 ? void 0 : _a.type) === 'template-only-component-js') {
66
+ return {
67
+ code: templateOnlyComponentSource(),
68
+ };
35
69
  }
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);
70
+ },
71
+ transform(code, id) {
72
+ if (!hbsFilter(id)) {
73
+ return null;
49
74
  }
75
+ return hbsToJS(code);
50
76
  },
51
77
  };
52
78
  }
53
- const templateOnlyComponent = `import templateOnly from '@ember/component/template-only';\n` + `export default templateOnly();\n`;
54
79
  function getMeta(context, id) {
55
80
  var _a, _b;
56
81
  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'];
@@ -61,56 +86,4 @@ function getMeta(context, id) {
61
86
  return null;
62
87
  }
63
88
  }
64
- function correspondingTemplate(filename) {
65
- let { ext } = (0, path_1.parse)(filename);
66
- return filename.slice(0, filename.length - ext.length) + '.hbs';
67
- }
68
- async function maybeSynthesizeComponentJS(context, source, importer) {
69
- debug(`checking for template-only component: %s`, source);
70
- let templateResolution = await context.resolve(correspondingTemplate(source), importer, {
71
- skipSelf: true,
72
- custom: {
73
- embroider: {
74
- // we don't want to recurse into the whole embroider compatbility
75
- // resolver here. It has presumably already steered our request to the
76
- // correct place. All we want to do is slightly modify the request we
77
- // were given (changing the extension) and check if that would resolve
78
- // instead.
79
- //
80
- // Currently this guard is only actually exercised in rollup, not in
81
- // vite, due to https://github.com/vitejs/vite/issues/13852
82
- enableCustomResolver: false,
83
- },
84
- },
85
- });
86
- if (!templateResolution) {
87
- return null;
88
- }
89
- debug(`emitting template only component: %s`, templateResolution.id);
90
- // we're trying to resolve a JS module but only the corresponding HBS
91
- // file exists. Synthesize the template-only component JS.
92
- return {
93
- id: templateResolution.id.replace(/\.hbs$/, '.js'),
94
- meta: {
95
- 'rollup-hbs-plugin': {
96
- type: 'template-only-component-js',
97
- },
98
- },
99
- };
100
- }
101
- const hbsFilter = (0, pluginutils_1.createFilter)('**/*.hbs');
102
- function maybeRewriteHBS(resolution) {
103
- if (!hbsFilter(resolution.id)) {
104
- return null;
105
- }
106
- debug('emitting hbs rewrite: %s', resolution.id);
107
- return {
108
- ...resolution,
109
- meta: {
110
- 'rollup-hbs-plugin': {
111
- type: 'template',
112
- },
113
- },
114
- };
115
- }
116
89
  //# sourceMappingURL=hbs.js.map
package/src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AErE,qEAAqE;IACrE,0DAA0D;IAC1D,OAAO;QACL,EAAE,EAAE,kBAAkB,CAAC,EAAE,CAAC,OAAO,CAAC,QAAQ,EAAE,KAAK,CAAC;QAClD,IAAI,EAAE;YACJ,mBAAmB,EAAE;gBACnB,IAAI,EAAE,4BAA4B;aACnC;SACF;KACF,CAAC;AACJ,CAAC;AAED,MAAM,SAAS,GAAG,IAAA,0BAAY,EAAC,UAAU,CAAC,CAAC;AAE3C,SAAS,eAAe,CAAC,UAAsB;IAC7C,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,EAAE,CAAC,EAAE,CAAC;QAC9B,OAAO,IAAI,CAAC;IACd,CAAC;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":"AAAA,OAAO,EAAE,YAAY,EAAE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Filter } from '@rollup/pluginutils';\nimport type { PluginContext } from 'rollup';\nimport type { Plugin } from 'vite';\nimport {\n hbsToJS,\n ResolverLoader,\n needsSyntheticComponentJS,\n isInComponents,\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 // vite already has extension search fallback for extensionless imports.\n // This is different, it covers an explicit .js import fallback to the\n // corresponding hbs.\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);\n if (syntheticId && isInComponents(resolution.id, resolverLoader.resolver.packageCache)) {\n return {\n id: syntheticId,\n meta: {\n 'rollup-hbs-plugin': {\n type: 'template-only-component-js',\n },\n },\n };\n }\n\n return resolution;\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,9 +1,11 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.optimizeDeps = optimizeDeps;
4
- function optimizeDeps() {
1
+ import { esBuildResolver } from './esbuild-resolver.js';
2
+ export function optimizeDeps() {
5
3
  return {
6
4
  exclude: ['@embroider/macros'],
5
+ extensions: ['.hbs', '.gjs', '.gts'],
6
+ esbuildOptions: {
7
+ plugins: [esBuildResolver()],
8
+ },
7
9
  };
8
10
  }
9
11
  //# sourceMappingURL=optimize-deps.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"optimize-deps.js","sourceRoot":"","sources":["optimize-deps.ts"],"names":[],"mappings":";;AAKA,oCAIC;AAJD,SAAgB,YAAY;IAC1B,OAAO;QACL,OAAO,EAAE,CAAC,mBAAmB,CAAC;KAC/B,CAAC;AACJ,CAAC","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":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAOxD,MAAM,UAAU,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,eAAe,EAAE,CAAC;SAC7B;KACF,CAAC;AACJ,CAAC","sourcesContent":["import { esBuildResolver } from './esbuild-resolver.js';\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
@@ -1,52 +1,108 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RollupModuleRequest = exports.virtualPrefix = void 0;
4
- const core_1 = require("@embroider/core");
5
- exports.virtualPrefix = 'embroider_virtual:';
6
- class RollupModuleRequest {
7
- static from(source, importer, custom) {
1
+ import core from '@embroider/core';
2
+ const { cleanUrl, getUrlQueryParams } = core;
3
+ export const virtualPrefix = 'embroider_virtual:';
4
+ export class RollupModuleRequest {
5
+ static from(context, source, importer, custom) {
8
6
  var _a, _b, _c;
9
7
  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
8
  return;
11
9
  }
12
10
  if (source && importer && source[0] !== '\0') {
13
11
  let nonVirtual;
14
- if (importer.startsWith(exports.virtualPrefix)) {
15
- nonVirtual = importer.slice(exports.virtualPrefix.length);
12
+ if (importer.startsWith(virtualPrefix)) {
13
+ nonVirtual = importer.slice(virtualPrefix.length);
16
14
  }
17
15
  else {
18
16
  nonVirtual = importer;
19
17
  }
20
18
  // strip query params off the importer
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);
19
+ let fromFile = cleanUrl(nonVirtual);
20
+ let importerQueryParams = getUrlQueryParams(nonVirtual);
21
+ // strip query params off the source but keep track of them
22
+ // we use regexp-based methods over a URL object because the
23
+ // source can be a relative path.
24
+ let cleanSource = cleanUrl(source);
25
+ let queryParams = getUrlQueryParams(source);
26
+ 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
27
  }
24
28
  }
25
- constructor(specifier, fromFile, meta) {
29
+ constructor(context, specifier, fromFile, meta, isNotFound, resolvedTo, queryParams, importerQueryParams) {
30
+ this.context = context;
26
31
  this.specifier = specifier;
27
32
  this.fromFile = fromFile;
28
33
  this.meta = meta;
34
+ this.isNotFound = isNotFound;
35
+ this.resolvedTo = resolvedTo;
36
+ this.queryParams = queryParams;
37
+ this.importerQueryParams = importerQueryParams;
38
+ }
39
+ get debugType() {
40
+ return 'rollup';
29
41
  }
30
42
  get isVirtual() {
31
- return this.specifier.startsWith(exports.virtualPrefix);
43
+ return this.specifier.startsWith(virtualPrefix);
44
+ }
45
+ get specifierWithQueryParams() {
46
+ return `${this.specifier}${this.queryParams}`;
47
+ }
48
+ get fromFileWithQueryParams() {
49
+ return `${this.fromFile}${this.importerQueryParams}`;
32
50
  }
33
51
  alias(newSpecifier) {
34
- return new RollupModuleRequest(newSpecifier, this.fromFile, this.meta);
52
+ return new RollupModuleRequest(this.context, newSpecifier, this.fromFile, this.meta, false, undefined, this.queryParams, this.importerQueryParams);
35
53
  }
36
54
  rehome(newFromFile) {
37
55
  if (this.fromFile === newFromFile) {
38
56
  return this;
39
57
  }
40
58
  else {
41
- return new RollupModuleRequest(this.specifier, newFromFile, this.meta);
59
+ return new RollupModuleRequest(this.context, this.specifier, newFromFile, this.meta, false, undefined, this.queryParams, this.importerQueryParams);
42
60
  }
43
61
  }
44
62
  virtualize(filename) {
45
- return new RollupModuleRequest(exports.virtualPrefix + filename, this.fromFile, this.meta);
63
+ return new RollupModuleRequest(this.context, virtualPrefix + filename, this.fromFile, this.meta, false, undefined, this.queryParams, this.importerQueryParams);
46
64
  }
47
65
  withMeta(meta) {
48
- return new RollupModuleRequest(this.specifier, this.fromFile, meta);
66
+ return new RollupModuleRequest(this.context, this.specifier, this.fromFile, meta, this.isNotFound, this.resolvedTo, this.queryParams, this.importerQueryParams);
67
+ }
68
+ notFound() {
69
+ return new RollupModuleRequest(this.context, this.specifier, this.fromFile, this.meta, true, undefined, this.queryParams, this.importerQueryParams);
70
+ }
71
+ async defaultResolve() {
72
+ if (this.isVirtual) {
73
+ return {
74
+ type: 'found',
75
+ filename: this.specifier,
76
+ result: { id: this.specifierWithQueryParams, resolvedBy: this.fromFileWithQueryParams },
77
+ isVirtual: this.isVirtual,
78
+ };
79
+ }
80
+ if (this.isNotFound) {
81
+ // TODO: we can make sure this looks correct in rollup & vite output when a
82
+ // user encounters it
83
+ let err = new Error(`module not found ${this.specifierWithQueryParams}`);
84
+ err.code = 'MODULE_NOT_FOUND';
85
+ return { type: 'not_found', err };
86
+ }
87
+ let result = await this.context.resolve(this.specifierWithQueryParams, this.fromFileWithQueryParams, {
88
+ skipSelf: true,
89
+ custom: {
90
+ embroider: {
91
+ enableCustomResolver: false,
92
+ meta: this.meta,
93
+ },
94
+ },
95
+ });
96
+ if (result) {
97
+ let { pathname } = new URL(result.id, 'http://example.com');
98
+ return { type: 'found', filename: pathname, result, isVirtual: this.isVirtual };
99
+ }
100
+ else {
101
+ return { type: 'not_found', err: undefined };
102
+ }
103
+ }
104
+ resolveTo(resolution) {
105
+ return new RollupModuleRequest(this.context, this.specifier, this.fromFile, this.meta, this.isNotFound, resolution, this.queryParams, this.importerQueryParams);
49
106
  }
50
107
  }
51
- exports.RollupModuleRequest = RollupModuleRequest;
52
108
  //# sourceMappingURL=request.js.map
@@ -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,CAAC;YACvD,OAAO;QACT,CAAC;QAED,IAAI,MAAM,IAAI,QAAQ,IAAI,MAAM,CAAC,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC;YAC7C,IAAI,UAAkB,CAAC;YACvB,IAAI,QAAQ,CAAC,UAAU,CAAC,qBAAa,CAAC,EAAE,CAAC;gBACvC,UAAU,GAAG,QAAQ,CAAC,KAAK,CAAC,qBAAa,CAAC,MAAM,CAAC,CAAC;YACpD,CAAC;iBAAM,CAAC;gBACN,UAAU,GAAG,QAAQ,CAAC;YACxB,CAAC;YAED,sCAAsC;YACtC,IAAI,QAAQ,GAAG,IAAA,eAAQ,EAAC,UAAU,CAAC,CAAC;YACpC,OAAO,IAAI,mBAAmB,CAAC,MAAM,EAAE,QAAQ,EAAE,MAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,SAAS,0CAAE,IAAI,CAAC,CAAC;QAC5E,CAAC;IACH,CAAC;IAED,YACW,SAAiB,EACjB,QAAgB,EAChB,IAAqC;QAFrC,cAAS,GAAT,SAAS,CAAQ;QACjB,aAAQ,GAAR,QAAQ,CAAQ;QAChB,SAAI,GAAJ,IAAI,CAAiC;IAC7C,CAAC;IAEJ,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,qBAAa,CAAC,CAAC;IAClD,CAAC;IAED,KAAK,CAAC,YAAoB;QACxB,OAAO,IAAI,mBAAmB,CAAC,YAAY,EAAE,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,IAAI,CAAS,CAAC;IACjF,CAAC;IACD,MAAM,CAAC,WAAmB;QACxB,IAAI,IAAI,CAAC,QAAQ,KAAK,WAAW,EAAE,CAAC;YAClC,OAAO,IAAI,CAAC;QACd,CAAC;aAAM,CAAC;YACN,OAAO,IAAI,mBAAmB,CAAC,IAAI,CAAC,SAAS,EAAE,WAAW,EAAE,IAAI,CAAC,IAAI,CAAS,CAAC;QACjF,CAAC;IACH,CAAC;IACD,UAAU,CAAC,QAAgB;QACzB,OAAO,IAAI,mBAAmB,CAAC,qBAAa,GAAG,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,IAAI,CAAS,CAAC;IAC7F,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,OAAO,IAAI,MAAM,iBAAiB,CAAC;AACnC,MAAM,EAAE,QAAQ,EAAE,iBAAiB,EAAE,GAAG,IAAI,CAAC;AAG7C,MAAM,CAAC,MAAM,aAAa,GAAG,oBAAoB,CAAC;AAElD,MAAM,OAAO,mBAAmB;IAC9B,MAAM,CAAC,IAAI,CACT,OAAsB,EACtB,MAAc,EACd,QAA4B,EAC5B,MAAuC;;QAEvC,IAAI,CAAC,CAAC,MAAA,MAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,SAAS,0CAAE,oBAAoB,mCAAI,IAAI,CAAC,EAAE,CAAC;YACvD,OA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;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","sourcesContent":["import type { ModuleRequest, Resolution } from '@embroider/core';\nimport core from '@embroider/core';\nconst { cleanUrl, getUrlQueryParams } = 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);\n let queryParams = getUrlQueryParams(source);\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"]}