@embroider/vite 0.2.1 → 0.2.2-unstable.0552afa
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/index.d.ts +4 -1
- package/index.mjs +6 -1
- package/package.json +25 -11
- package/src/assets.d.ts +2 -0
- package/src/assets.js +87 -0
- package/src/assets.js.map +1 -0
- package/src/build.d.ts +3 -0
- package/src/build.js +60 -0
- package/src/build.js.map +1 -0
- package/src/classic-ember-support.d.ts +1 -0
- package/src/classic-ember-support.js +9 -0
- package/src/classic-ember-support.js.map +1 -0
- package/src/content-for.d.ts +2 -0
- package/src/content-for.js +19 -0
- package/src/content-for.js.map +1 -0
- package/src/ember.d.ts +6 -0
- package/src/ember.js +43 -0
- package/src/ember.js.map +1 -0
- package/src/esbuild-request.d.ts +36 -0
- package/src/esbuild-request.js +138 -0
- package/src/esbuild-request.js.map +1 -0
- package/src/esbuild-resolver.d.ts +2 -0
- package/src/esbuild-resolver.js +158 -0
- package/src/esbuild-resolver.js.map +1 -0
- package/src/hbs.js +62 -89
- package/src/hbs.js.map +1 -1
- package/src/optimize-deps.js +6 -4
- package/src/optimize-deps.js.map +1 -1
- package/src/request.d.ts +20 -11
- package/src/request.js +71 -41
- package/src/request.js.map +1 -1
- package/src/resolver.js +150 -41
- package/src/resolver.js.map +1 -1
- package/src/scripts.js +17 -37
- package/src/scripts.js.map +1 -1
- package/src/template-tag.js +7 -37
- package/src/template-tag.js.map +1 -1
- package/src/addons.d.ts +0 -1
- package/src/addons.js +0 -23
- package/src/addons.js.map +0 -1
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { transformAsync } from '@babel/core';
|
|
2
|
+
import core, { ModuleRequest } from '@embroider/core';
|
|
3
|
+
const { ResolverLoader, virtualContent, needsSyntheticComponentJS, isInComponents } = core;
|
|
4
|
+
import fs from 'fs-extra';
|
|
5
|
+
const { readFileSync } = fs;
|
|
6
|
+
import { EsBuildRequestAdapter } 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
|
+
async function transformAndAssert(src, filename) {
|
|
16
|
+
const result = await transformAsync(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
|
+
async 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 = await 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 = ModuleRequest.create(EsBuildRequestAdapter.create, {
|
|
51
|
+
packageCache: resolverLoader.resolver.packageCache,
|
|
52
|
+
phase,
|
|
53
|
+
build,
|
|
54
|
+
kind,
|
|
55
|
+
path,
|
|
56
|
+
importer,
|
|
57
|
+
pluginData,
|
|
58
|
+
});
|
|
59
|
+
if (!request) {
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
let resolution = await resolverLoader.resolver.resolve(request);
|
|
63
|
+
switch (resolution.type) {
|
|
64
|
+
case 'found':
|
|
65
|
+
case 'ignored':
|
|
66
|
+
return resolution.result;
|
|
67
|
+
case 'not_found':
|
|
68
|
+
return resolution.err;
|
|
69
|
+
default:
|
|
70
|
+
throw assertNever(resolution);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
// template-only-component synthesis
|
|
74
|
+
build.onResolve({ filter: /./ }, async ({ path, importer, namespace, resolveDir, pluginData, kind }) => {
|
|
75
|
+
if (pluginData === null || pluginData === void 0 ? void 0 : pluginData.embroiderHBSResolving) {
|
|
76
|
+
// reentrance
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
let result = await build.resolve(path, {
|
|
80
|
+
namespace,
|
|
81
|
+
resolveDir,
|
|
82
|
+
importer,
|
|
83
|
+
kind,
|
|
84
|
+
// avoid reentrance
|
|
85
|
+
pluginData: { ...pluginData, embroiderHBSResolving: true },
|
|
86
|
+
});
|
|
87
|
+
if (result.errors.length === 0 && !result.external) {
|
|
88
|
+
let syntheticPath = needsSyntheticComponentJS(path, result.path);
|
|
89
|
+
if (syntheticPath && isInComponents(result.path, resolverLoader.resolver.packageCache)) {
|
|
90
|
+
return { path: syntheticPath, namespace: 'embroider-template-only-component' };
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return result;
|
|
94
|
+
});
|
|
95
|
+
if (phase === 'bundling') {
|
|
96
|
+
// during bundling phase, we need to provide our own extension
|
|
97
|
+
// searching. We do it here in its own resolve plugin so that it's
|
|
98
|
+
// sitting beneath both embroider resolver and template-only-component
|
|
99
|
+
// synthesizer, since both expect the ambient system to have extension
|
|
100
|
+
// search.
|
|
101
|
+
build.onResolve({ filter: /./ }, async ({ path, importer, namespace, resolveDir, pluginData, kind }) => {
|
|
102
|
+
if (pluginData === null || pluginData === void 0 ? void 0 : pluginData.embroiderExtensionResolving) {
|
|
103
|
+
// reentrance
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
let firstResult;
|
|
107
|
+
for (let requestName of extensionSearch(path, resolverLoader.resolver.options.resolvableExtensions)) {
|
|
108
|
+
let result = await build.resolve(requestName, {
|
|
109
|
+
namespace,
|
|
110
|
+
resolveDir,
|
|
111
|
+
importer,
|
|
112
|
+
kind,
|
|
113
|
+
// avoid reentrance
|
|
114
|
+
pluginData: { ...pluginData, embroiderExtensionResolving: true },
|
|
115
|
+
});
|
|
116
|
+
if (result.errors.length > 0) {
|
|
117
|
+
// if extension search fails, we want to let the first failure be the
|
|
118
|
+
// one that propagates, so that the error message makes sense.
|
|
119
|
+
firstResult = result;
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
return result;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return firstResult;
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
// we need to handle everything from one of our three special namespaces:
|
|
129
|
+
build.onLoad({ namespace: 'embroider-template-only-component', filter: /./ }, onLoad);
|
|
130
|
+
build.onLoad({ namespace: 'embroider-virtual', filter: /./ }, onLoad);
|
|
131
|
+
build.onLoad({ namespace: 'embroider-template-tag', filter: /./ }, onLoad);
|
|
132
|
+
// we need to handle all hbs
|
|
133
|
+
build.onLoad({ filter: /\.hbs$/ }, onLoad);
|
|
134
|
+
// we need to handle all GJS (to preprocess) and JS (to run macros)
|
|
135
|
+
build.onLoad({ filter: /\.g?[jt]s$/ }, onLoad);
|
|
136
|
+
},
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
function detectPhase(build) {
|
|
140
|
+
var _a;
|
|
141
|
+
let plugins = ((_a = build.initialOptions.plugins) !== null && _a !== void 0 ? _a : []).map(p => p.name);
|
|
142
|
+
if (plugins.includes('vite:dep-pre-bundle')) {
|
|
143
|
+
return 'bundling';
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
return 'other';
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
function* extensionSearch(specifier, extensions) {
|
|
150
|
+
yield specifier;
|
|
151
|
+
// when there's no explicit extension, we may do extension search
|
|
152
|
+
if (extname(specifier) === '') {
|
|
153
|
+
for (let ext of extensions) {
|
|
154
|
+
yield specifier + ext;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
//# 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,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,IAAI,EAAE,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACtD,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,CAAC;AAC5B,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAE/B,MAAM,qBAAqB,GACzB,8DAA8D,GAAG,kCAAkC,CAAC;AAEtG,MAAM,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AAE,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 { transformAsync } from '@babel/core';\nimport core, { ModuleRequest } from '@embroider/core';\nconst { ResolverLoader, virtualContent, needsSyntheticComponentJS, isInComponents } = core;\nimport fs from 'fs-extra';\nconst { readFileSync } = fs;\nimport { EsBuildRequestAdapter } 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 async function transformAndAssert(src: string, filename: string): Promise<string> {\n const result = await transformAsync(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 async function onLoad({ path, namespace }: { path: string; namespace: string }): Promise<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 = await 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 = ModuleRequest.create(EsBuildRequestAdapter.create, {\n packageCache: 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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
|
|
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
|
-
|
|
28
|
-
|
|
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
|
-
|
|
33
|
-
if (
|
|
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
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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/hbs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hbs.js","sourceRoot":"","sources":["hbs.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"hbs.js","sourceRoot":"","sources":["hbs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAGnD,OAAO,EACL,OAAO,EACP,cAAc,EACd,yBAAyB,EACzB,cAAc,EACd,2BAA2B,EAC3B,gBAAgB,GACjB,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C;oBAChB,OAAO,IAAI,CAAC;gBACd,CAAC;YACH,CAAC;YAED,IAAI,WAAW,GAAG,yBAAyB,CAAC,MAAM,EAAE,UAAU,CAAC,EAAE,CAAC,CAAC;YACnE,IAAI,WAAW,IAAI,cAAc,CAAC,UAAU,CAAC,EAAE,EAAE,cAAc,CAAC,QAAQ,CAAC,YAAY,CAAC,EAAE,CAAC;gBACvF,OAAO;oBACL,EAAE,EAAE,WAAW;oBACf,IAAI,EAAE;wBACJ,mBAAmB,EAAE;4BACnB,IAAI,EAAE,4BAA4B;yBACnC;qBACF;iBACF,CAAC;YACJ,CAAC;YAED,OAAO,UAAU,CAAC;QACpB,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,2BAA2B,EAAE;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,OAAO,CAAC,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 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"]}
|
package/src/optimize-deps.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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
|
package/src/optimize-deps.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"optimize-deps.js","sourceRoot":"","sources":["optimize-deps.ts"],"names":[],"mappings":"
|
|
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,23 @@
|
|
|
1
|
-
import type { ModuleRequest } from '@embroider/core';
|
|
1
|
+
import type { ModuleRequest, RequestAdapter, RequestAdapterCreate, Resolution } from '@embroider/core';
|
|
2
|
+
import type { PluginContext, ResolveIdResult } from 'rollup';
|
|
2
3
|
export declare const virtualPrefix = "embroider_virtual:";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
interface Init {
|
|
5
|
+
context: PluginContext;
|
|
6
|
+
source: string;
|
|
7
|
+
importer: string | undefined;
|
|
8
|
+
custom: Record<string, any> | undefined;
|
|
9
|
+
}
|
|
10
|
+
export declare class RollupRequestAdapter implements RequestAdapter<Resolution<ResolveIdResult>> {
|
|
11
|
+
private context;
|
|
12
|
+
private queryParams;
|
|
13
|
+
private importerQueryParams;
|
|
14
|
+
static create: RequestAdapterCreate<Init, Resolution<ResolveIdResult>>;
|
|
8
15
|
private constructor();
|
|
9
|
-
get
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
16
|
+
get debugType(): string;
|
|
17
|
+
private specifierWithQueryParams;
|
|
18
|
+
private fromFileWithQueryParams;
|
|
19
|
+
virtualResponse(request: ModuleRequest<Resolution<ResolveIdResult>>, virtualFileName: string): Resolution<ResolveIdResult>;
|
|
20
|
+
notFoundResponse(_request: ModuleRequest<Resolution<ResolveIdResult>>): Resolution<ResolveIdResult>;
|
|
21
|
+
resolve(request: ModuleRequest<Resolution<ResolveIdResult>>): Promise<Resolution<ResolveIdResult>>;
|
|
14
22
|
}
|
|
23
|
+
export {};
|
package/src/request.js
CHANGED
|
@@ -1,52 +1,82 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
if (source && importer && source[0] !== '\0') {
|
|
13
|
-
let nonVirtual;
|
|
14
|
-
if (importer.startsWith(exports.virtualPrefix)) {
|
|
15
|
-
nonVirtual = importer.slice(exports.virtualPrefix.length);
|
|
16
|
-
}
|
|
17
|
-
else {
|
|
18
|
-
nonVirtual = importer;
|
|
19
|
-
}
|
|
20
|
-
// 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);
|
|
23
|
-
}
|
|
1
|
+
import core from '@embroider/core';
|
|
2
|
+
const { cleanUrl, getUrlQueryParams } = core;
|
|
3
|
+
export const virtualPrefix = 'embroider_virtual:';
|
|
4
|
+
export class RollupRequestAdapter {
|
|
5
|
+
constructor(context, queryParams, importerQueryParams) {
|
|
6
|
+
this.context = context;
|
|
7
|
+
this.queryParams = queryParams;
|
|
8
|
+
this.importerQueryParams = importerQueryParams;
|
|
9
|
+
}
|
|
10
|
+
get debugType() {
|
|
11
|
+
return 'rollup';
|
|
24
12
|
}
|
|
25
|
-
|
|
26
|
-
this.
|
|
27
|
-
this.fromFile = fromFile;
|
|
28
|
-
this.meta = meta;
|
|
13
|
+
specifierWithQueryParams(specifier) {
|
|
14
|
+
return `${specifier}${this.queryParams}`;
|
|
29
15
|
}
|
|
30
|
-
|
|
31
|
-
return this.
|
|
16
|
+
fromFileWithQueryParams(fromFile) {
|
|
17
|
+
return `${fromFile}${this.importerQueryParams}`;
|
|
32
18
|
}
|
|
33
|
-
|
|
34
|
-
|
|
19
|
+
virtualResponse(request, virtualFileName) {
|
|
20
|
+
let specifier = virtualPrefix + virtualFileName;
|
|
21
|
+
return {
|
|
22
|
+
type: 'found',
|
|
23
|
+
filename: specifier,
|
|
24
|
+
result: {
|
|
25
|
+
id: this.specifierWithQueryParams(specifier),
|
|
26
|
+
resolvedBy: this.fromFileWithQueryParams(request.fromFile),
|
|
27
|
+
},
|
|
28
|
+
isVirtual: true,
|
|
29
|
+
};
|
|
35
30
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
31
|
+
notFoundResponse(_request) {
|
|
32
|
+
let err = new Error(`module not found ${this.specifierWithQueryParams}`);
|
|
33
|
+
err.code = 'MODULE_NOT_FOUND';
|
|
34
|
+
return { type: 'not_found', err };
|
|
35
|
+
}
|
|
36
|
+
async resolve(request) {
|
|
37
|
+
let result = await this.context.resolve(this.specifierWithQueryParams(request.specifier), this.fromFileWithQueryParams(request.fromFile), {
|
|
38
|
+
skipSelf: true,
|
|
39
|
+
custom: {
|
|
40
|
+
embroider: {
|
|
41
|
+
enableCustomResolver: false,
|
|
42
|
+
meta: request.meta,
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
if (result) {
|
|
47
|
+
let { pathname } = new URL(result.id, 'http://example.com');
|
|
48
|
+
return { type: 'found', filename: pathname, result, isVirtual: false };
|
|
39
49
|
}
|
|
40
50
|
else {
|
|
41
|
-
return
|
|
51
|
+
return { type: 'not_found', err: undefined };
|
|
42
52
|
}
|
|
43
53
|
}
|
|
44
|
-
|
|
45
|
-
|
|
54
|
+
}
|
|
55
|
+
RollupRequestAdapter.create = ({ context, source, importer, custom, }) => {
|
|
56
|
+
var _a, _b, _c;
|
|
57
|
+
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)) {
|
|
58
|
+
return;
|
|
46
59
|
}
|
|
47
|
-
|
|
48
|
-
|
|
60
|
+
if (source && importer && source[0] !== '\0') {
|
|
61
|
+
let nonVirtual;
|
|
62
|
+
if (importer.startsWith(virtualPrefix)) {
|
|
63
|
+
nonVirtual = importer.slice(virtualPrefix.length);
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
nonVirtual = importer;
|
|
67
|
+
}
|
|
68
|
+
// strip query params off the importer
|
|
69
|
+
let fromFile = cleanUrl(nonVirtual);
|
|
70
|
+
let importerQueryParams = getUrlQueryParams(nonVirtual);
|
|
71
|
+
// strip query params off the source but keep track of them
|
|
72
|
+
// we use regexp-based methods over a URL object because the
|
|
73
|
+
// source can be a relative path.
|
|
74
|
+
let cleanSource = cleanUrl(source);
|
|
75
|
+
let queryParams = getUrlQueryParams(source);
|
|
76
|
+
return {
|
|
77
|
+
initialState: { specifier: cleanSource, fromFile, meta: (_c = custom === null || custom === void 0 ? void 0 : custom.embroider) === null || _c === void 0 ? void 0 : _c.meta },
|
|
78
|
+
adapter: new RollupRequestAdapter(context, queryParams, importerQueryParams),
|
|
79
|
+
};
|
|
49
80
|
}
|
|
50
|
-
}
|
|
51
|
-
exports.RollupModuleRequest = RollupModuleRequest;
|
|
81
|
+
};
|
|
52
82
|
//# sourceMappingURL=request.js.map
|
package/src/request.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request.js","sourceRoot":"","sources":["request.ts"],"names":[],"mappings":"
|
|
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;AASlD,MAAM,OAAO,oBAAoB;IAmC/B,YACU,OAAsB,EACtB,WAAmB,EACnB,mBAA2B;QAF3B,YAAO,GAAP,OAAO,CAAe;QACtB,gBAAW,GAAX,WAAW,CAAQ;QACnB,wBAAmB,GAAnB,mBAAmB,CAAQ;IAClC,CAAC;IAEJ,IAAI,SAAS;QACX,OAAO,QAAQ,CAAC;IAClB,CAAC;IAEO,wBAAwB,CAAC,SAAiB;QAChD,OAAO,GAAG,SAAS,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;IAC3C,CAAC;IAEO,uBAAuB,CAAC,QAAgB;QAC9C,OAAO,GAAG,QAAQ,GAAG,IAAI,CAAC,mBAAmB,E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RequestAdapter, RequestAdapterCreate, 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\ninterface Init {\n context: PluginContext;\n source: string;\n importer: string | undefined;\n custom: Record<string, any> | undefined;\n}\n\nexport class RollupRequestAdapter implements RequestAdapter<Resolution<ResolveIdResult>> {\n static create: RequestAdapterCreate<Init, Resolution<ResolveIdResult>> = ({\n context,\n source,\n importer,\n custom,\n }: Init) => {\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 {\n initialState: { specifier: cleanSource, fromFile, meta: custom?.embroider?.meta },\n adapter: new RollupRequestAdapter(context, queryParams, importerQueryParams),\n };\n }\n };\n\n private constructor(\n private context: PluginContext,\n private queryParams: string,\n private importerQueryParams: string\n ) {}\n\n get debugType() {\n return 'rollup';\n }\n\n private specifierWithQueryParams(specifier: string): string {\n return `${specifier}${this.queryParams}`;\n }\n\n private fromFileWithQueryParams(fromFile: string): string {\n return `${fromFile}${this.importerQueryParams}`;\n }\n\n virtualResponse(\n request: ModuleRequest<Resolution<ResolveIdResult>>,\n virtualFileName: string\n ): Resolution<ResolveIdResult> {\n let specifier = virtualPrefix + virtualFileName;\n return {\n type: 'found',\n filename: specifier,\n result: {\n id: this.specifierWithQueryParams(specifier),\n resolvedBy: this.fromFileWithQueryParams(request.fromFile),\n },\n isVirtual: true,\n };\n }\n\n notFoundResponse(_request: ModuleRequest<Resolution<ResolveIdResult>>): Resolution<ResolveIdResult> {\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\n async resolve(request: ModuleRequest<Resolution<ResolveIdResult>>): Promise<Resolution<ResolveIdResult>> {\n let result = await this.context.resolve(\n this.specifierWithQueryParams(request.specifier),\n this.fromFileWithQueryParams(request.fromFile),\n {\n skipSelf: true,\n custom: {\n embroider: {\n enableCustomResolver: false,\n meta: request.meta,\n },\n },\n }\n );\n if (result) {\n let { pathname } = new URL(result.id, 'http://example.com');\n return { type: 'found', filename: pathname, result, isVirtual: false };\n } else {\n return { type: 'not_found', err: undefined };\n }\n }\n}\n"]}
|