@embroider/core 3.5.1-unstable.fc482ba → 3.5.2
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/package.json +11 -22
- package/src/app-files.d.ts +5 -3
- package/src/app-files.js +8 -25
- package/src/app-files.js.map +1 -1
- package/src/asset.d.ts +32 -0
- package/src/asset.js +3 -0
- package/src/asset.js.map +1 -0
- package/src/ember-html.d.ts +43 -0
- package/src/ember-html.js +110 -0
- package/src/ember-html.js.map +1 -0
- package/src/index.d.ts +5 -5
- package/src/index.js +4 -3
- package/src/index.js.map +1 -1
- package/src/measure-concat.js +2 -1
- package/src/measure-concat.js.map +1 -1
- package/src/messages.js.map +1 -1
- package/src/module-resolver.d.ts +61 -24
- package/src/module-resolver.js +310 -469
- package/src/module-resolver.js.map +1 -1
- package/src/node-resolve.d.ts +6 -31
- package/src/node-resolve.js +44 -112
- package/src/node-resolve.js.map +1 -1
- package/src/options.d.ts +7 -0
- package/src/options.js +1 -0
- package/src/options.js.map +1 -1
- package/src/packager.d.ts +8 -0
- package/src/packager.js +9 -0
- package/src/packager.js.map +1 -1
- package/src/portable-babel-config.d.ts +11 -0
- package/src/portable-babel-config.js +132 -0
- package/src/portable-babel-config.js.map +1 -0
- package/src/portable-babel-launcher.d.ts +6 -0
- package/src/portable-babel-launcher.js +75 -0
- package/src/portable-babel-launcher.js.map +1 -0
- package/src/resolver-loader.js +1 -8
- package/src/resolver-loader.js.map +1 -1
- package/src/to-broccoli-plugin.d.ts +8 -0
- package/src/to-broccoli-plugin.js +30 -0
- package/src/to-broccoli-plugin.js.map +1 -0
- package/src/virtual-content.d.ts +12 -32
- package/src/virtual-content.js +184 -83
- package/src/virtual-content.js.map +1 -1
- package/src/module-request.d.ts +0 -44
- package/src/module-request.js +0 -100
- package/src/module-request.js.map +0 -1
- package/src/module-resolver-options.d.ts +0 -42
- package/src/module-resolver-options.js +0 -164
- package/src/module-resolver-options.js.map +0 -1
- package/src/virtual-entrypoint.d.ts +0 -21
- package/src/virtual-entrypoint.js +0 -273
- package/src/virtual-entrypoint.js.map +0 -1
- package/src/virtual-route-entrypoint.d.ts +0 -10
- package/src/virtual-route-entrypoint.js +0 -62
- package/src/virtual-route-entrypoint.js.map +0 -1
- package/src/virtual-test-support-styles.d.ts +0 -7
- package/src/virtual-test-support-styles.js +0 -61
- package/src/virtual-test-support-styles.js.map +0 -1
- package/src/virtual-test-support.d.ts +0 -7
- package/src/virtual-test-support.js +0 -65
- package/src/virtual-test-support.js.map +0 -1
- package/src/virtual-vendor-styles.d.ts +0 -8
- package/src/virtual-vendor-styles.js +0 -83
- package/src/virtual-vendor-styles.js.map +0 -1
- package/src/virtual-vendor.d.ts +0 -7
- package/src/virtual-vendor.js +0 -53
- package/src/virtual-vendor.js.map +0 -1
- package/types/virtual/index.d.ts +0 -9
- package/types/virtual/index.js +0 -3
package/src/node-resolve.js
CHANGED
@@ -1,130 +1,62 @@
|
|
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.
|
7
|
-
exports.nodeResolve = nodeResolve;
|
8
|
-
const virtual_content_1 = require("./virtual-content");
|
3
|
+
exports.resolve = resolve;
|
9
4
|
const path_1 = require("path");
|
10
5
|
const shared_internals_1 = require("@embroider/shared-internals");
|
11
|
-
|
12
|
-
//
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
let
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
};
|
29
|
-
}
|
30
|
-
virtualResponse(_request, virtual) {
|
31
|
-
return {
|
32
|
-
type: 'found',
|
33
|
-
filename: virtual.specifier,
|
34
|
-
virtual,
|
35
|
-
result: {
|
36
|
-
type: 'virtual',
|
37
|
-
content: (0, virtual_content_1.virtualContent)(virtual, this.resolver).src,
|
38
|
-
filename: virtual.specifier,
|
39
|
-
},
|
40
|
-
};
|
6
|
+
function resolve(specifier, fromFile, extensions = ['.hbs.js', '.hbs']) {
|
7
|
+
// require.resolve does not like when we resolve from virtual paths.
|
8
|
+
// That is, a request like "../thing.js" from
|
9
|
+
// "/a/real/path/VIRTUAL_SUBDIR/virtual.js" has an unambiguous target of
|
10
|
+
// "/a/real/path/thing.js", but require.resolve won't do that path
|
11
|
+
// adjustment until after checking whether VIRTUAL_SUBDIR actually
|
12
|
+
// exists.
|
13
|
+
//
|
14
|
+
// We can do the path adjustments before doing require.resolve.
|
15
|
+
let fromDir = (0, path_1.dirname)(fromFile);
|
16
|
+
if (!(0, path_1.isAbsolute)(specifier) && specifier.startsWith('.')) {
|
17
|
+
let targetPath = (0, path_1.resolve)(fromDir, specifier);
|
18
|
+
let newFromDir = (0, path_1.dirname)(targetPath);
|
19
|
+
if (fromDir !== newFromDir) {
|
20
|
+
specifier = (0, shared_internals_1.explicitRelative)(newFromDir, targetPath);
|
21
|
+
fromDir = newFromDir;
|
22
|
+
}
|
41
23
|
}
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
//
|
50
|
-
// We can do the path adjustments before doing require.resolve.
|
51
|
-
let { specifier } = request;
|
52
|
-
let fromDir = (0, path_1.dirname)(request.fromFile);
|
53
|
-
if (!(0, path_1.isAbsolute)(specifier) && specifier.startsWith('.')) {
|
54
|
-
let targetPath = (0, path_1.resolve)(fromDir, specifier);
|
55
|
-
let newFromDir = (0, path_1.dirname)(targetPath);
|
56
|
-
if (fromDir !== newFromDir) {
|
57
|
-
specifier = (0, shared_internals_1.explicitRelative)(newFromDir, targetPath);
|
58
|
-
fromDir = newFromDir;
|
59
|
-
}
|
24
|
+
let initialError;
|
25
|
+
for (let candidate of candidates(specifier, extensions)) {
|
26
|
+
let filename;
|
27
|
+
try {
|
28
|
+
filename = require.resolve(candidate, {
|
29
|
+
paths: [fromDir],
|
30
|
+
});
|
60
31
|
}
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
try {
|
65
|
-
filename = require.resolve(candidate, {
|
66
|
-
paths: [fromDir],
|
67
|
-
});
|
32
|
+
catch (err) {
|
33
|
+
if (err.code !== 'MODULE_NOT_FOUND') {
|
34
|
+
throw err;
|
68
35
|
}
|
69
|
-
|
70
|
-
|
71
|
-
throw err;
|
72
|
-
}
|
73
|
-
if (!initialError) {
|
74
|
-
initialError = err;
|
75
|
-
}
|
76
|
-
continue;
|
36
|
+
if (!initialError) {
|
37
|
+
initialError = err;
|
77
38
|
}
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
39
|
+
continue;
|
40
|
+
}
|
41
|
+
if (filename.endsWith('.hbs') && !candidate.endsWith('.hbs')) {
|
42
|
+
// Evaluating the `handlebars` NPM package installs a Node extension
|
43
|
+
// that puts `*.hbs` in the automatic search path. But we can't control
|
44
|
+
// its priority, and it's really important to us that `.hbs` cannot
|
45
|
+
// shadow other extensions with higher priority. For example, when both
|
46
|
+
// `.ts` and `.hbs` exist, resolving is supposed to find the `.ts`.
|
47
|
+
//
|
48
|
+
// This covers the case where we found an hbs "by accident", when we
|
49
|
+
// weren't actually expecting it.
|
50
|
+
continue;
|
90
51
|
}
|
91
|
-
return { type: '
|
52
|
+
return { type: 'found', result: { type: 'real', filename } };
|
92
53
|
}
|
54
|
+
return { type: 'not_found', err: initialError };
|
93
55
|
}
|
94
|
-
exports.NodeRequestAdapter = NodeRequestAdapter;
|
95
|
-
NodeRequestAdapter.create = ({ resolver, specifier, fromFile, extensions }) => {
|
96
|
-
return {
|
97
|
-
initialState: {
|
98
|
-
specifier,
|
99
|
-
fromFile,
|
100
|
-
meta: undefined,
|
101
|
-
},
|
102
|
-
adapter: new NodeRequestAdapter(resolver, extensions),
|
103
|
-
};
|
104
|
-
};
|
105
|
-
const defaultExtensions = ['.hbs.js', '.hbs'];
|
106
56
|
function* candidates(specifier, extensions) {
|
107
57
|
yield specifier;
|
108
58
|
for (let ext of extensions) {
|
109
59
|
yield `${specifier}${ext}`;
|
110
60
|
}
|
111
61
|
}
|
112
|
-
async function nodeResolve(resolver, specifier, fromFile, opts) {
|
113
|
-
var _a;
|
114
|
-
let request = module_request_1.ModuleRequest.create(NodeRequestAdapter.create, {
|
115
|
-
resolver,
|
116
|
-
fromFile,
|
117
|
-
specifier,
|
118
|
-
extensions: (_a = opts === null || opts === void 0 ? void 0 : opts.extensions) !== null && _a !== void 0 ? _a : defaultExtensions,
|
119
|
-
});
|
120
|
-
let resolution = await resolver.resolve(request);
|
121
|
-
switch (resolution.type) {
|
122
|
-
case 'not_found':
|
123
|
-
return resolution;
|
124
|
-
case 'found':
|
125
|
-
return resolution.result;
|
126
|
-
default:
|
127
|
-
throw (0, assert_never_1.default)(resolution);
|
128
|
-
}
|
129
|
-
}
|
130
62
|
//# sourceMappingURL=node-resolve.js.map
|
package/src/node-resolve.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"node-resolve.js","sourceRoot":"","sources":["node-resolve.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"node-resolve.js","sourceRoot":"","sources":["node-resolve.ts"],"names":[],"mappings":";;AAGA,0BAyDC;AA5DD,+BAAmE;AACnE,kEAA+D;AAE/D,SAAgB,OAAO,CACrB,SAAiB,EACjB,QAAgB,EAChB,UAAU,GAAG,CAAC,SAAS,EAAE,MAAM,CAAC;IAEhC,oEAAoE;IACpE,6CAA6C;IAC7C,wEAAwE;IACxE,kEAAkE;IAClE,kEAAkE;IAClE,UAAU;IACV,EAAE;IACF,+DAA+D;IAC/D,IAAI,OAAO,GAAG,IAAA,cAAO,EAAC,QAAQ,CAAC,CAAC;IAChC,IAAI,CAAC,IAAA,iBAAU,EAAC,SA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,IAAI,EAAE,WAAW,EAAE,GAAG,EAAE,YAAY,EAAE,CAAC;AAClD,CAAC;AAED,QAAQ,CAAC,CAAC,UAAU,CAAC,SAAiB,EAAE,UAAoB;IAC1D,MAAM,SAAS,CAAC;IAEhB,KAAK,IAAI,GAAG,IAAI,UAAU,EAAE,CAAC;QAC3B,MAAM,GAAG,SAAS,GAAG,GAAG,EAAE,CAAC;IAC7B,CAAC;AACH,CAAC","sourcesContent":["import { dirname, isAbsolute, resolve as pathResolve } from 'path';\nimport { explicitRelative } from '@embroider/shared-internals';\n\nexport function resolve(\n specifier: string,\n fromFile: string,\n extensions = ['.hbs.js', '.hbs']\n): { type: 'found'; result: { type: 'real'; filename: string } } | { type: 'not_found'; err: Error } {\n // require.resolve does not like when we resolve from virtual paths.\n // That is, a request like \"../thing.js\" from\n // \"/a/real/path/VIRTUAL_SUBDIR/virtual.js\" has an unambiguous target of\n // \"/a/real/path/thing.js\", but require.resolve won't do that path\n // adjustment until after checking whether VIRTUAL_SUBDIR actually\n // exists.\n //\n // We can do the path adjustments before doing require.resolve.\n let fromDir = dirname(fromFile);\n if (!isAbsolute(specifier) && specifier.startsWith('.')) {\n let targetPath = pathResolve(fromDir, specifier);\n let newFromDir = dirname(targetPath);\n if (fromDir !== newFromDir) {\n specifier = explicitRelative(newFromDir, targetPath);\n fromDir = newFromDir;\n }\n }\n\n let initialError;\n\n for (let candidate of candidates(specifier, extensions)) {\n let filename;\n try {\n filename = require.resolve(candidate, {\n paths: [fromDir],\n });\n } catch (err) {\n if (err.code !== 'MODULE_NOT_FOUND') {\n throw err;\n }\n\n if (!initialError) {\n initialError = err;\n }\n\n continue;\n }\n if (filename.endsWith('.hbs') && !candidate.endsWith('.hbs')) {\n // Evaluating the `handlebars` NPM package installs a Node extension\n // that puts `*.hbs` in the automatic search path. But we can't control\n // its priority, and it's really important to us that `.hbs` cannot\n // shadow other extensions with higher priority. For example, when both\n // `.ts` and `.hbs` exist, resolving is supposed to find the `.ts`.\n //\n // This covers the case where we found an hbs \"by accident\", when we\n // weren't actually expecting it.\n continue;\n }\n return { type: 'found', result: { type: 'real' as 'real', filename } };\n }\n\n return { type: 'not_found', err: initialError };\n}\n\nfunction* candidates(specifier: string, extensions: string[]) {\n yield specifier;\n\n for (let ext of extensions) {\n yield `${specifier}${ext}`;\n }\n}\n"]}
|
package/src/options.d.ts
CHANGED
@@ -55,10 +55,17 @@ export default interface Options {
|
|
55
55
|
staticInvokables?: boolean;
|
56
56
|
splitAtRoutes?: (RegExp | string)[];
|
57
57
|
staticAppPaths?: string[];
|
58
|
+
skipBabel?: {
|
59
|
+
package: string;
|
60
|
+
semverRange?: string;
|
61
|
+
}[];
|
58
62
|
pluginHints?: {
|
59
63
|
resolve: string[];
|
60
64
|
useMethod?: string;
|
61
65
|
}[];
|
66
|
+
amdCompatibility?: false | 'cjs' | {
|
67
|
+
es: [string, string[]][];
|
68
|
+
};
|
62
69
|
}
|
63
70
|
export type CoreOptionsType = Required<Omit<Options, 'staticHelpers' | 'staticModifiers' | 'staticComponents' | 'staticInvokables'>> & Pick<Options, 'staticHelpers' | 'staticModifiers' | 'staticComponents' | 'staticInvokables'>;
|
64
71
|
export declare function optionsWithDefaults(options?: Options): CoreOptionsType;
|
package/src/options.js
CHANGED
package/src/options.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"options.js","sourceRoot":"","sources":["options.ts"],"names":[],"mappings":";;
|
1
|
+
{"version":3,"file":"options.js","sourceRoot":"","sources":["options.ts"],"names":[],"mappings":";;AA+JA,kDAYC;AAZD,SAAgB,mBAAmB,CAAC,OAAiB;IACnD,IAAI,QAAQ,GAAG;QACb,aAAa,EAAE,EAAE;QACjB,cAAc,EAAE,EAAE;QAClB,SAAS,EAAE,EAAE;QACb,WAAW,EAAE,EAAE;QACf,gBAAgB,EAAE,KAAc;KACjC,CAAC;IACF,IAAI,OAAO,EAAE,CAAC;QACZ,OAAO,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAC1C,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC","sourcesContent":["export default interface Options {\n /**\n * When true, we statically resolve all template helpers at build time. This\n * causes unused helpers to be left out of the build (\"tree shaking\" of\n * helpers).\n *\n * Defaults to false, which gives you greater compatibility with classic Ember\n * apps at the cost of bigger builds.\n *\n * Enabling this is a prerequisite for route splitting.\n *\n * @deprecated use staticInvokables instead\n */\n staticHelpers?: boolean;\n\n /**\n * When true, we statically resolve all modifiers at build time. This\n * causes unused modifiers to be left out of the build (\"tree shaking\" of\n * modifiers).\n *\n * Defaults to false, which gives you greater compatibility with classic Ember\n * apps at the cost of bigger builds.\n *\n * Enabling this is a prerequisite for route splitting.\n *\n * @deprecated use staticInvokables instead\n */\n staticModifiers?: boolean;\n\n /**\n * When true, we statically resolve all components at build time. This causes\n * unused components to be left out of the build (\"tree shaking\" of\n * components).\n *\n * Defaults to false, which gives you greater compatibility with classic Ember\n * apps at the cost of bigger builds.\n *\n * Enabling this is a prerequisite for route splitting.\n *\n * @deprecated use staticInvokables instead\n */\n staticComponents?: boolean;\n\n /**\n * When true, we statically resolve all components, modifiers, and helpers (collectively\n * knows as Invokables) at build time. This causes any unused Invokables to be left out\n * of the build if they are unused i.e. \"tree shaking\".\n *\n * Defaults to false which gives you greater compatibility with classic Ember apps at the\n * cost of bigger builds.\n *\n * This setting takes over from `staticHelpers`, `staticModifiers`, and `staticComponents`\n * because the Developer Experience was less than ideal if any of these settings did not\n * agree i.e. they all needed to be true or they all needed to be false.\n *\n * Enabling this is a prerequisite for route splitting.\n */\n staticInvokables?: boolean;\n\n // Enables per-route code splitting. Any route names that match these patterns\n // will be split out of the initial app payload. If you use this, you must\n // also add @embroider/router to your app. See [@embroider/router's\n // README](https://github.com/embroider-build/embroider/blob/main/packages/router/README.md)\n splitAtRoutes?: (RegExp | string)[];\n\n // Every file within your application's `app` directory is categorized as a\n // component, helper, modifier, route, route template, controller, or \"other\".\n //\n // This option lets you decide which \"other\" files should be loaded\n // statically. By default, all \"other\" files will be included in the build and\n // registered with Ember's runtime loader, because we can't know if somebody\n // is going to try to access them dynamically via Ember's resolver or AMD\n // runtime `require`.\n //\n // If you know that your files are only ever imported, you can list them here\n // and then they will only be included exactly where they're needed.\n //\n // Provide a list of directories or files relative to `/app`. For example\n //\n // staticAppPaths: ['lib']\n //\n // means that everything under your-project/app/lib will be loaded statically.\n //\n // This option has no effect on components (which are governed by\n // staticComponents), helpers (which are governed by staticHelpers), modifiers\n // (which are governed by staticModifiers) or the route-specific files (routes,\n // route templates, and controllers which are governed by splitAtRoutes).\n staticAppPaths?: string[];\n\n // By default, all modules that get imported into the app go through Babel, so\n // that all code will conform with your Babel targets. This option allows you\n // to turn Babel off for a particular package. You might need this to work\n // around a transpiler bug or you might use this as a build-performance\n // optimization if you've manually verified that a particular package doesn't\n // need transpilation to be safe in your target browsers.\n skipBabel?: { package: string; semverRange?: string }[];\n\n // This is a performance optimization that can help you avoid the \"Your build\n // is slower because some babel plugins are non-serializable\" penalty. If you\n // provide the locations of known non-serializable objects, we can discover\n // them and make them serializable.\n //\n // resolve is a list of paths to resolve, in a chain. This lets you resolve\n // your dependencies' dependencies, like: resolve: ['your-dependency',\n // 'inner-dependency/lib/transform']\n //\n // useMethod optionally lets you pick which property within the module to use.\n // If not provided, we use the module.exports itself.\n pluginHints?: { resolve: string[]; useMethod?: string }[];\n\n // Ember classically used a runtime AMD module loader.\n //\n // Embroider *can* locate the vast majority of modules statically, but when an\n // addon is doing something highly dynamic (like injecting AMD `define()`\n // statements directly into a <script>), we still may not be able to locate\n // them. So Embroider can emit a placeholder shim for the missing module that\n // attempts to locate it at runtime in the classic AMD loader.\n //\n // This shim can be generated as commonJS (cjs) or an ES module (es). The\n // default is cjs.\n //\n // CJS is useful when you're building in an environment that is tolerant of\n // mixed CJS and ES modules (like Webpack), because the set of exported names\n // from the module doesn't need to be known in advance. For this reason, CJS\n // shims are generated on-demand and are fully-automatic. This is the default\n // for maximum backward-compatibility.\n //\n // ES is useful when you're building in a strict ES module environment (like\n // Vite). It's fully spec-defined and doesn't suffer interoperability\n // complexities. The downside is, we can only emit a correct shim for a module\n // if you tell embroider what set of names it exports. Example:\n\n // emberExternals: {\n // es: [\n // // import { first, second } from \"my-library\";\n // ['my-library', ['first', 'second']],\n // // import Example from \"my-library/components/example\";\n // ['my-library/components/example', ['default']]\n // ];\n // }\n\n // It is not recommended to use `es` mode without also using\n // staticEmberSource, because without staticEmberSource ember itself needs\n // many external shims.\n //\n // false means we don't do any external shimming.\n amdCompatibility?:\n | false\n | 'cjs'\n | {\n es: [string, string[]][];\n };\n}\n\nexport type CoreOptionsType = Required<\n Omit<Options, 'staticHelpers' | 'staticModifiers' | 'staticComponents' | 'staticInvokables'>\n> &\n Pick<Options, 'staticHelpers' | 'staticModifiers' | 'staticComponents' | 'staticInvokables'>;\n\nexport function optionsWithDefaults(options?: Options): CoreOptionsType {\n let defaults = {\n splitAtRoutes: [],\n staticAppPaths: [],\n skipBabel: [],\n pluginHints: [],\n amdCompatibility: 'cjs' as const,\n };\n if (options) {\n return Object.assign(defaults, options);\n }\n return defaults;\n}\n"]}
|
package/src/packager.d.ts
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
import type { AppMeta } from '@embroider/shared-internals';
|
1
2
|
export interface Variant {
|
2
3
|
name: string;
|
3
4
|
runtime: 'all' | 'browser' | 'fastboot';
|
@@ -11,6 +12,13 @@ export interface Packager {
|
|
11
12
|
build(): Promise<void>;
|
12
13
|
}
|
13
14
|
export declare function applyVariantToBabelConfig(variant: Variant, babelConfig: any): any;
|
15
|
+
/**
|
16
|
+
* Get the app meta-data for a package
|
17
|
+
*/
|
18
|
+
export declare function getAppMeta(pathToVanillaApp: string): {
|
19
|
+
name: string;
|
20
|
+
"ember-addon": AppMeta;
|
21
|
+
};
|
14
22
|
/**
|
15
23
|
* Get the path to a cache directory in the recommended location
|
16
24
|
*
|
package/src/packager.js
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.applyVariantToBabelConfig = applyVariantToBabelConfig;
|
4
|
+
exports.getAppMeta = getAppMeta;
|
4
5
|
exports.getPackagerCacheDir = getPackagerCacheDir;
|
5
6
|
const shared_internals_1 = require("@embroider/shared-internals");
|
7
|
+
const fs_extra_1 = require("fs-extra");
|
6
8
|
const lodash_1 = require("lodash");
|
7
9
|
const path_1 = require("path");
|
8
10
|
function applyVariantToBabelConfig(variant, babelConfig) {
|
@@ -23,6 +25,13 @@ function applyVariantToBabelConfig(variant, babelConfig) {
|
|
23
25
|
}
|
24
26
|
return babelConfig;
|
25
27
|
}
|
28
|
+
/**
|
29
|
+
* Get the app meta-data for a package
|
30
|
+
*/
|
31
|
+
function getAppMeta(pathToVanillaApp) {
|
32
|
+
let pkg = JSON.parse((0, fs_extra_1.readFileSync)((0, path_1.join)(pathToVanillaApp, 'package.json'), 'utf8'));
|
33
|
+
return pkg;
|
34
|
+
}
|
26
35
|
/**
|
27
36
|
* Get the path to a cache directory in the recommended location
|
28
37
|
*
|
package/src/packager.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"packager.js","sourceRoot":"","sources":["packager.ts"],"names":[],"mappings":";;
|
1
|
+
{"version":3,"file":"packager.js","sourceRoot":"","sources":["packager.ts"],"names":[],"mappings":";;AAwEA,8DAkBC;AAKD,gCAGC;AAOD,kDAEC;AA1GD,kEAAqD;AACrD,uCAAwC;AACxC,mCAAmC;AACnC,+BAA4B;AAoE5B,SAAgB,yBAAyB,CAAC,OAAgB,EAAE,WAAgB;IAC1E,IAAI,OAAO,CAAC,OAAO,KAAK,UAAU,EAAE,CAAC;QACnC,WAAW,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,WAAW,CAAC,CAAC;QAC7C,IAAI,WAAW,CAAC,OAAO,EAAE,CAAC;YACxB,WAAW,CAAC,OAAO,GAAG,WAAW,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;QACpD,CAAC;aAAM,CAAC;YACN,WAAW,CAAC,OAAO,GAAG,EAAE,CAAC;QAC3B,CAAC;QACD,IAAI,WAAW,GAAG,WAAW,CAAC,OAAO,CAAC,IAAI,CACxC,CAAC,CAAM,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,2BAA2B,CACzE,CAAC;QACF,IAAI,WAAW,EAAE,CAAC;YAChB,IAAI,mBAAmB,GAAG,IAAA,kBAAS,EAAC,WAAW,CAAC,CAAC;YACjD,mBAAmB,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,QAAQ,GAAG,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;YACnE,WAAW,CAAC,OAAO,CAAC,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE,CAAC,EAAE,mBAAmB,CAAC,CAAC;QAC/F,CAAC;IACH,CAAC;IACD,OAAO,WAAW,CAAC;AACrB,CAAC;AAED;;GAEG;AACH,SAAgB,UAAU,CAAC,gBAAwB;IACjD,IAAI,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,IAAA,uBAAY,EAAC,IAAA,WAAI,EAAC,gBAAgB,EAAE,cAAc,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;IACnF,OAAO,GAA0D,CAAC;AACpE,CAAC;AAED;;;;GAIG;AACH,SAAgB,mBAAmB,CAAC,IAAY;IAC9C,OAAO,IAAA,WAAI,EAAC,yBAAM,EAAE,WAAW,EAAE,IAAI,CAAC,CAAC;AACzC,CAAC","sourcesContent":["import type { AppMeta } from '@embroider/shared-internals';\nimport { tmpdir } from '@embroider/shared-internals';\nimport { readFileSync } from 'fs-extra';\nimport { cloneDeep } from 'lodash';\nimport { join } from 'path';\n\n// This is a collection of flags that convey what kind of build you want. They\n// are intended to be generic across Packagers, and it's up to Packager authors\n// to support each option (or not).\nexport interface Variant {\n // descriptive name that can be used by the packager to label which output\n // goes with which variant.\n name: string;\n\n // Which runtime should this build work in? Dev builds will typically be \"all\"\n // because we produce a single build that works in browser and fastboot. But\n // production builds can be divided into a browser-only variant and a\n // fastboot-only variant so that each can be separately optimized.\n //\n // Note that if you build *only* a fastboot variant, you're unlikely to end up\n // with any assets that can boot and run in the browser too, so the typical\n // thing to do is to have to two variants and for the packager to use the\n // assets from the browser build to generate browser-facing <script> tags in\n // the output of the fastboot build.\n runtime: 'all' | 'browser' | 'fastboot';\n\n // true if this build should be optimized for production, at the cost of\n // slower builds and/or worse debuggability\n optimizeForProduction: boolean;\n}\n\nexport interface PackagerConstructor<Options> {\n new (\n // where on disk the packager will find the app it's supposed to build. The\n // app and its addons will necessarily already be in v2 format, which is\n // what makes a Packager a cleanly separable stage that needs only a small\n // amount of ember-specific knowledge.\n inputPath: string,\n // where the packager should write the packaged app.\n outputPath: string,\n // list of active build variants. There is always at least one variant, but\n // there can be many.\n //\n // The main requirement for correctness is that the Packager is required to\n // apply each variant to the babel and template-compiler configs that it\n // finds in the app in order to build that variant.\n //\n // It is up to each Packager to decide how to combine the output from the\n // multiple variants. It might choose to just put them in separate\n // subdirectories of `outputPath`, or it might know how to combine them\n // correctly into one build that will run each variant under the appropriate\n // conditions.\n //\n // Not all packagers will support all arbitrary combinations of variants.\n variants: Variant[],\n // if possible, the packager should direct its console output through this\n // hook.\n consoleWrite: (message: string) => void,\n // A packager can have whatever custom options type it wants here. If the\n // packager is based on a third-party tool, this is where that tool's\n // configuration can go.\n options?: Options\n ): Packager;\n\n // a description for this packager that aids debugging & profiling\n annotation: string;\n}\n\nexport interface Packager {\n build(): Promise<void>;\n}\n\nexport function applyVariantToBabelConfig(variant: Variant, babelConfig: any) {\n if (variant.runtime === 'fastboot') {\n babelConfig = Object.assign({}, babelConfig);\n if (babelConfig.plugins) {\n babelConfig.plugins = babelConfig.plugins.slice();\n } else {\n babelConfig.plugins = [];\n }\n let macroPlugin = babelConfig.plugins.find(\n (p: any) => Array.isArray(p) && p[1] && p[1].embroiderMacrosConfigMarker\n );\n if (macroPlugin) {\n let modifiedMacroPlugin = cloneDeep(macroPlugin);\n modifiedMacroPlugin[1].globalConfig.fastboot = { isRunning: true };\n babelConfig.plugins.splice(babelConfig.plugins.indexOf(macroPlugin), 1, modifiedMacroPlugin);\n }\n }\n return babelConfig;\n}\n\n/**\n * Get the app meta-data for a package\n */\nexport function getAppMeta(pathToVanillaApp: string) {\n let pkg = JSON.parse(readFileSync(join(pathToVanillaApp, 'package.json'), 'utf8'));\n return pkg as unknown as { name: string; 'ember-addon': AppMeta };\n}\n\n/**\n * Get the path to a cache directory in the recommended location\n *\n * This ensures they have exactly the same lifetime as some of embroider's own caches.\n */\nexport function getPackagerCacheDir(name: string): string {\n return join(tmpdir, 'embroider', name);\n}\n"]}
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import type { TransformOptions } from '@babel/core';
|
2
|
+
import type { PortableHint } from './portable';
|
3
|
+
export type ResolveOptions = {
|
4
|
+
basedir: string;
|
5
|
+
} | {
|
6
|
+
resolve: (name: string) => any;
|
7
|
+
};
|
8
|
+
export declare function makePortable(config: TransformOptions, resolveOptions: ResolveOptions, hints: PortableHint[]): {
|
9
|
+
config: TransformOptions;
|
10
|
+
isParallelSafe: boolean;
|
11
|
+
};
|
@@ -0,0 +1,132 @@
|
|
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.makePortable = makePortable;
|
7
|
+
const path_1 = require("path");
|
8
|
+
const resolve_1 = __importDefault(require("resolve"));
|
9
|
+
const portable_1 = require("./portable");
|
10
|
+
function makePortable(config, resolveOptions, hints) {
|
11
|
+
return new PortableBabelConfig(resolveOptions, hints).convert(config);
|
12
|
+
}
|
13
|
+
class PortableBabelConfig {
|
14
|
+
constructor(resolveOptions, hints) {
|
15
|
+
this.hints = hints;
|
16
|
+
if ('resolve' in resolveOptions) {
|
17
|
+
this.resolve = resolveOptions.resolve;
|
18
|
+
}
|
19
|
+
else {
|
20
|
+
this.basedir = resolveOptions.basedir;
|
21
|
+
this.resolve = (name) => resolve_1.default.sync(name, { basedir: resolveOptions.basedir });
|
22
|
+
}
|
23
|
+
}
|
24
|
+
convert(config) {
|
25
|
+
let portable = new portable_1.Portable({
|
26
|
+
hints: this.hints,
|
27
|
+
dehydrate: (value, accessPath) => {
|
28
|
+
// this custom dehydrate hook handles babel plugins & presets. If we're
|
29
|
+
// not looking at plugins or presets, continue with stock Portable
|
30
|
+
// behavior
|
31
|
+
if (accessPath.length !== 2 || (accessPath[0] !== 'plugins' && accessPath[0] !== 'presets')) {
|
32
|
+
return undefined;
|
33
|
+
}
|
34
|
+
// standardize to always handle an array
|
35
|
+
if (!Array.isArray(value)) {
|
36
|
+
value = [value];
|
37
|
+
}
|
38
|
+
let [plugin, argument, asName] = value;
|
39
|
+
// string plugins need to get resolved correctly into absolute paths,
|
40
|
+
// so they will really be portable
|
41
|
+
if (typeof plugin === 'string') {
|
42
|
+
plugin = this.resolveBabelPlugin(plugin);
|
43
|
+
}
|
44
|
+
// next we deal with serializability. Our Portable system already
|
45
|
+
// understands the protocol used by ember-cli-babel to identify plugin
|
46
|
+
// classes and get back to their serializable forms, so this will
|
47
|
+
// handle that case.
|
48
|
+
let dehydrated = portable.dehydrate([plugin, argument, asName], accessPath.concat('_internal'));
|
49
|
+
if (dehydrated.needsHydrate) {
|
50
|
+
// we can eliminate the need for rehydration by going through our own
|
51
|
+
// portable babel launcher
|
52
|
+
return {
|
53
|
+
value: [
|
54
|
+
(0, path_1.join)(__dirname, 'portable-babel-launcher.js'),
|
55
|
+
{ module: dehydrated.value[0], arg: dehydrated.value[1], hints: this.hints },
|
56
|
+
dehydrated.value[2] || `portable-babel-launcher-${accessPath[1]}`,
|
57
|
+
],
|
58
|
+
needsHydrate: false,
|
59
|
+
isParallelSafe: dehydrated.isParallelSafe,
|
60
|
+
};
|
61
|
+
}
|
62
|
+
else {
|
63
|
+
// trim back down our array, because trailing undefined will get
|
64
|
+
// converted into null via json.stringify, and babel will complain
|
65
|
+
// about that.
|
66
|
+
while (dehydrated.value.length > 0 && dehydrated.value[dehydrated.value.length - 1] == null) {
|
67
|
+
dehydrated.value.pop();
|
68
|
+
}
|
69
|
+
if (dehydrated.value.length === 1) {
|
70
|
+
dehydrated.value = dehydrated.value[0];
|
71
|
+
}
|
72
|
+
return {
|
73
|
+
value: dehydrated.value,
|
74
|
+
needsHydrate: dehydrated.needsHydrate,
|
75
|
+
isParallelSafe: dehydrated.isParallelSafe,
|
76
|
+
};
|
77
|
+
}
|
78
|
+
},
|
79
|
+
});
|
80
|
+
let result = portable.dehydrate(config);
|
81
|
+
if (result.needsHydrate) {
|
82
|
+
throw new Error(`bug: portable babel configs aren't supposed to need hydration`);
|
83
|
+
}
|
84
|
+
return { config: result.value, isParallelSafe: result.isParallelSafe };
|
85
|
+
}
|
86
|
+
// babel lets you use relative paths, absolute paths, package names, and
|
87
|
+
// package name shorthands.
|
88
|
+
//
|
89
|
+
// my-plugin -> my-plugin
|
90
|
+
// my-plugin -> babel-plugin-my-plugin
|
91
|
+
// @me/thing -> @me/thing
|
92
|
+
// @me/thing -> @me/babel-plugin-thing
|
93
|
+
// ./here -> /your/app/here
|
94
|
+
// /tmp/there -> /tmp/there
|
95
|
+
//
|
96
|
+
resolveBabelPlugin(name) {
|
97
|
+
try {
|
98
|
+
return this.resolve(name);
|
99
|
+
}
|
100
|
+
catch (err) {
|
101
|
+
if (err.code !== 'MODULE_NOT_FOUND') {
|
102
|
+
throw err;
|
103
|
+
}
|
104
|
+
if (name.startsWith('.') || name.startsWith('/')) {
|
105
|
+
throw err;
|
106
|
+
}
|
107
|
+
try {
|
108
|
+
let expanded;
|
109
|
+
if (name.startsWith('@')) {
|
110
|
+
let [space, pkg, ...rest] = name.split('/');
|
111
|
+
expanded = [space, `babel-plugin-${pkg}`, ...rest].join('/');
|
112
|
+
}
|
113
|
+
else {
|
114
|
+
expanded = `babel-plugin-${name}`;
|
115
|
+
}
|
116
|
+
return this.resolve(expanded);
|
117
|
+
}
|
118
|
+
catch (err2) {
|
119
|
+
if (err2.code !== 'MODULE_NOT_FOUND') {
|
120
|
+
throw err2;
|
121
|
+
}
|
122
|
+
if (this.basedir) {
|
123
|
+
throw new Error(`unable to resolve babel plugin ${name} from ${this.basedir}`);
|
124
|
+
}
|
125
|
+
else {
|
126
|
+
throw new Error(`unable to resolve babel plugin ${name}`);
|
127
|
+
}
|
128
|
+
}
|
129
|
+
}
|
130
|
+
}
|
131
|
+
}
|
132
|
+
//# sourceMappingURL=portable-babel-config.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"portable-babel-config.js","sourceRoot":"","sources":["portable-babel-config.ts"],"names":[],"mappings":";;;;;AAQA,oCAMC;AAbD,+BAA4B;AAC5B,sDAA8B;AAE9B,yCAAsC;AAItC,SAAgB,YAAY,CAC1B,MAAwB,EACxB,cAA8B,EAC9B,KAAqB;IAErB,OAAO,IAAI,mBAAmB,CAAC,cAAc,EAAE,KAAK,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;AACxE,CAAC;AAED,MAAM,mBAAmB;IAIvB,YAAY,cAA8B,EAAU,KAAqB;QAArB,UAAK,GAAL,KAAK,CAAgB;QACvE,IAAI,SAAS,IAAI,cAAc,EAAE,CAAC;YAChC,IAAI,CAAC,OAAO,GAAG,cAAc,CAAC,OAAO,CAAC;QACxC,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,OAAO,GAAG,cAAc,CAAC,OAAO,CAAC;YACtC,IAAI,CAAC,OAAO,GAAG,CAAC,IAAY,EAAE,EAAE,CAAC,iBAAO,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,OAAO,EAAE,cAAc,CAAC,OAAO,EAAE,CAAC,CAAC;QA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K,CAAC,kCAAkC,IAAI,EAAE,CAAC,CAAC;gBAC5D,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;CACF","sourcesContent":["import type { TransformOptions } from '@babel/core';\nimport { join } from 'path';\nimport resolve from 'resolve';\nimport type { PortableHint } from './portable';\nimport { Portable } from './portable';\n\nexport type ResolveOptions = { basedir: string } | { resolve: (name: string) => any };\n\nexport function makePortable(\n config: TransformOptions,\n resolveOptions: ResolveOptions,\n hints: PortableHint[]\n): { config: TransformOptions; isParallelSafe: boolean } {\n return new PortableBabelConfig(resolveOptions, hints).convert(config);\n}\n\nclass PortableBabelConfig {\n private resolve: (name: string) => any;\n private basedir: string | undefined;\n\n constructor(resolveOptions: ResolveOptions, private hints: PortableHint[]) {\n if ('resolve' in resolveOptions) {\n this.resolve = resolveOptions.resolve;\n } else {\n this.basedir = resolveOptions.basedir;\n this.resolve = (name: string) => resolve.sync(name, { basedir: resolveOptions.basedir });\n }\n }\n\n convert(config: TransformOptions): { config: TransformOptions; isParallelSafe: boolean } {\n let portable: Portable = new Portable({\n hints: this.hints,\n dehydrate: (value: any, accessPath: string[]) => {\n // this custom dehydrate hook handles babel plugins & presets. If we're\n // not looking at plugins or presets, continue with stock Portable\n // behavior\n if (accessPath.length !== 2 || (accessPath[0] !== 'plugins' && accessPath[0] !== 'presets')) {\n return undefined;\n }\n\n // standardize to always handle an array\n if (!Array.isArray(value)) {\n value = [value];\n }\n\n let [plugin, argument, asName] = value;\n\n // string plugins need to get resolved correctly into absolute paths,\n // so they will really be portable\n if (typeof plugin === 'string') {\n plugin = this.resolveBabelPlugin(plugin);\n }\n\n // next we deal with serializability. Our Portable system already\n // understands the protocol used by ember-cli-babel to identify plugin\n // classes and get back to their serializable forms, so this will\n // handle that case.\n let dehydrated = portable.dehydrate([plugin, argument, asName], accessPath.concat('_internal'));\n\n if (dehydrated.needsHydrate) {\n // we can eliminate the need for rehydration by going through our own\n // portable babel launcher\n return {\n value: [\n join(__dirname, 'portable-babel-launcher.js'),\n { module: dehydrated.value[0], arg: dehydrated.value[1], hints: this.hints },\n dehydrated.value[2] || `portable-babel-launcher-${accessPath[1]}`,\n ],\n needsHydrate: false,\n isParallelSafe: dehydrated.isParallelSafe,\n };\n } else {\n // trim back down our array, because trailing undefined will get\n // converted into null via json.stringify, and babel will complain\n // about that.\n while (dehydrated.value.length > 0 && dehydrated.value[dehydrated.value.length - 1] == null) {\n dehydrated.value.pop();\n }\n if (dehydrated.value.length === 1) {\n dehydrated.value = dehydrated.value[0];\n }\n return {\n value: dehydrated.value,\n needsHydrate: dehydrated.needsHydrate,\n isParallelSafe: dehydrated.isParallelSafe,\n };\n }\n },\n });\n let result = portable.dehydrate(config);\n if (result.needsHydrate) {\n throw new Error(`bug: portable babel configs aren't supposed to need hydration`);\n }\n return { config: result.value, isParallelSafe: result.isParallelSafe };\n }\n\n // babel lets you use relative paths, absolute paths, package names, and\n // package name shorthands.\n //\n // my-plugin -> my-plugin\n // my-plugin -> babel-plugin-my-plugin\n // @me/thing -> @me/thing\n // @me/thing -> @me/babel-plugin-thing\n // ./here -> /your/app/here\n // /tmp/there -> /tmp/there\n //\n private resolveBabelPlugin(name: string) {\n try {\n return this.resolve(name);\n } catch (err) {\n if (err.code !== 'MODULE_NOT_FOUND') {\n throw err;\n }\n if (name.startsWith('.') || name.startsWith('/')) {\n throw err;\n }\n try {\n let expanded;\n if (name.startsWith('@')) {\n let [space, pkg, ...rest] = name.split('/');\n expanded = [space, `babel-plugin-${pkg}`, ...rest].join('/');\n } else {\n expanded = `babel-plugin-${name}`;\n }\n return this.resolve(expanded);\n } catch (err2) {\n if (err2.code !== 'MODULE_NOT_FOUND') {\n throw err2;\n }\n if (this.basedir) {\n throw new Error(`unable to resolve babel plugin ${name} from ${this.basedir}`);\n } else {\n throw new Error(`unable to resolve babel plugin ${name}`);\n }\n }\n }\n }\n}\n"]}
|
@@ -0,0 +1,75 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.default = babelLauncher;
|
4
|
+
const portable_1 = require("./portable");
|
5
|
+
function babelLauncher(babel, launch, key) {
|
6
|
+
let p = new portable_1.Portable({ hints: launch.hints });
|
7
|
+
let hydrated = p.hydrate(launch);
|
8
|
+
let module;
|
9
|
+
if (typeof hydrated.module === 'string') {
|
10
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
11
|
+
module = require(hydrated.module);
|
12
|
+
if (module.__esModule) {
|
13
|
+
module = module.default;
|
14
|
+
}
|
15
|
+
}
|
16
|
+
else {
|
17
|
+
module = hydrated.module;
|
18
|
+
}
|
19
|
+
let plugin = module.call(this, babel, hydrated.arg, key);
|
20
|
+
let innerStates = new WeakMap();
|
21
|
+
function convertState(state) {
|
22
|
+
let innerState = innerStates.get(state);
|
23
|
+
if (!innerState) {
|
24
|
+
innerState = Object.assign({}, state, { opts: hydrated.arg });
|
25
|
+
innerStates.set(state, innerState);
|
26
|
+
}
|
27
|
+
return innerState;
|
28
|
+
}
|
29
|
+
function wrap1(original) {
|
30
|
+
if (typeof original === 'function') {
|
31
|
+
return function (file) {
|
32
|
+
return original.call(convertState(this), file);
|
33
|
+
};
|
34
|
+
}
|
35
|
+
}
|
36
|
+
function wrap2(original) {
|
37
|
+
return function (path, state) {
|
38
|
+
return original.call(convertState(this), path, convertState(state));
|
39
|
+
};
|
40
|
+
}
|
41
|
+
let visitorProxy = {
|
42
|
+
get(target, prop) {
|
43
|
+
let original = target[prop];
|
44
|
+
if (typeof original === 'function') {
|
45
|
+
return wrap2(original);
|
46
|
+
}
|
47
|
+
if (original && typeof original === 'object') {
|
48
|
+
let wrapped = {};
|
49
|
+
if (typeof original.exit === 'function') {
|
50
|
+
wrapped.exit = wrap2(original.exit);
|
51
|
+
}
|
52
|
+
if (typeof original.enter === 'function') {
|
53
|
+
wrapped.enter = wrap2(original.enter);
|
54
|
+
}
|
55
|
+
return wrapped;
|
56
|
+
}
|
57
|
+
return original;
|
58
|
+
},
|
59
|
+
};
|
60
|
+
return new Proxy(plugin, {
|
61
|
+
get(target, prop) {
|
62
|
+
let original = target[prop];
|
63
|
+
switch (prop) {
|
64
|
+
case 'pre':
|
65
|
+
case 'post':
|
66
|
+
return wrap1(original);
|
67
|
+
case 'visitor':
|
68
|
+
return new Proxy(original, visitorProxy);
|
69
|
+
default:
|
70
|
+
return original;
|
71
|
+
}
|
72
|
+
},
|
73
|
+
});
|
74
|
+
}
|
75
|
+
//# sourceMappingURL=portable-babel-launcher.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"portable-babel-launcher.js","sourceRoot":"","sources":["portable-babel-launcher.ts"],"names":[],"mappings":";;AAGA,gCA+EC;AAjFD,yCAAsC;AAEtC,SAAwB,aAAa,CAEnC,KAAU,EACV,MAAwD,EACxD,GAAW;IAEX,IAAI,CAAC,GAAG,IAAI,mBAAQ,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC;IAC9C,IAAI,QAAQ,GAAG,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IACjC,IAAI,MAAM,CAAC;IACX,IAAI,OAAO,QAAQ,CAAC,MAAM,KAAK,QAAQ,EAAE,CAAC;QACxC,iEAAiE;QACjE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;QAClC,IAAI,MAAM,CAAC,UAAU,EAAE,CAAC;YACtB,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC;QAC1B,CAAC;IACH,CAAC;SAAM,CAAC;QACN,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC;IAC3B,CAAC;IAED,IAAI,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IACzD,IAAI,WAAW,GAAG,IAAI,OAAO,EAAE,CAAC;IAEhC,SAAS,YAAY,CAAC,KAAU;QAC9B,IAAI,UAAU,GAAG,WAAW,CA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I,OAAO,QAAQ,CAAC,KAAK,KAAK,UAAU,EAAE,CAAC;oBACzC,OAAO,CAAC,KAAK,GAAG,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;gBACxC,CAAC;gBACD,OAAO,OAAO,CAAC;YACjB,CAAC;YACD,OAAO,QAAQ,CAAC;QAClB,CAAC;KACF,CAAC;IAEF,OAAO,IAAI,KAAK,CAAC,MAAM,EAAE;QACvB,GAAG,CAAC,MAAM,EAAE,IAAI;YACd,IAAI,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;YAC5B,QAAQ,IAAI,EAAE,CAAC;gBACb,KAAK,KAAK,CAAC;gBACX,KAAK,MAAM;oBACT,OAAO,KAAK,CAAC,QAAQ,CAAC,CAAC;gBACzB,KAAK,SAAS;oBACZ,OAAO,IAAI,KAAK,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;gBAC3C;oBACE,OAAO,QAAQ,CAAC;YACpB,CAAC;QACH,CAAC;KACF,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type { PortableHint } from './portable';\nimport { Portable } from './portable';\n\nexport default function babelLauncher(\n this: any,\n babel: any,\n launch: { module: any; arg: any; hints: PortableHint[] },\n key: string\n) {\n let p = new Portable({ hints: launch.hints });\n let hydrated = p.hydrate(launch);\n let module;\n if (typeof hydrated.module === 'string') {\n // eslint-disable-next-line @typescript-eslint/no-require-imports\n module = require(hydrated.module);\n if (module.__esModule) {\n module = module.default;\n }\n } else {\n module = hydrated.module;\n }\n\n let plugin = module.call(this, babel, hydrated.arg, key);\n let innerStates = new WeakMap();\n\n function convertState(state: any) {\n let innerState = innerStates.get(state);\n if (!innerState) {\n innerState = Object.assign({}, state, { opts: hydrated.arg });\n innerStates.set(state, innerState);\n }\n return innerState;\n }\n\n function wrap1(original: any) {\n if (typeof original === 'function') {\n return function (this: any, file: any) {\n return original.call(convertState(this), file);\n };\n }\n }\n\n function wrap2(original: Function) {\n return function (this: any, path: any, state: any) {\n return original.call(convertState(this), path, convertState(state));\n };\n }\n\n let visitorProxy = {\n get(target: any, prop: string) {\n let original = target[prop];\n if (typeof original === 'function') {\n return wrap2(original);\n }\n if (original && typeof original === 'object') {\n let wrapped: any = {};\n if (typeof original.exit === 'function') {\n wrapped.exit = wrap2(original.exit);\n }\n if (typeof original.enter === 'function') {\n wrapped.enter = wrap2(original.enter);\n }\n return wrapped;\n }\n return original;\n },\n };\n\n return new Proxy(plugin, {\n get(target, prop) {\n let original = target[prop];\n switch (prop) {\n case 'pre':\n case 'post':\n return wrap1(original);\n case 'visitor':\n return new Proxy(original, visitorProxy);\n default:\n return original;\n }\n },\n });\n}\n"]}
|