@wyw-in-js/transform 0.1.0 → 0.2.0
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/esm/index.js +5 -1
- package/esm/index.js.map +1 -1
- package/esm/options/loadBabelOptions.js +1 -1
- package/esm/options/loadBabelOptions.js.map +1 -1
- package/esm/plugins/babel-transform.js +2 -2
- package/esm/plugins/babel-transform.js.map +1 -1
- package/esm/plugins/collector.js +4 -4
- package/esm/plugins/collector.js.map +1 -1
- package/esm/plugins/preeval.js +11 -11
- package/esm/plugins/preeval.js.map +1 -1
- package/esm/plugins/shaker.js +5 -5
- package/esm/plugins/shaker.js.map +1 -1
- package/esm/shaker.js +2 -2
- package/esm/shaker.js.map +1 -1
- package/esm/transform/Entrypoint.helpers.js +1 -2
- package/esm/transform/Entrypoint.helpers.js.map +1 -1
- package/esm/transform/Entrypoint.js +4 -4
- package/esm/transform/Entrypoint.js.map +1 -1
- package/esm/transform/generators/collect.js +3 -2
- package/esm/transform/generators/collect.js.map +1 -1
- package/esm/transform/generators/evalFile.js +6 -6
- package/esm/transform/generators/evalFile.js.map +1 -1
- package/esm/transform/generators/extract.js +18 -14
- package/esm/transform/generators/extract.js.map +1 -1
- package/esm/transform/generators/transform.js +2 -2
- package/esm/transform/generators/transform.js.map +1 -1
- package/esm/transform/generators/workflow.js +3 -3
- package/esm/transform/generators/workflow.js.map +1 -1
- package/esm/transform/helpers/{loadLinariaOptions.js → loadWywOptions.js} +5 -5
- package/esm/transform/helpers/loadWywOptions.js.map +1 -0
- package/esm/transform.js +11 -10
- package/esm/transform.js.map +1 -1
- package/esm/types.js.map +1 -1
- package/esm/utils/ShakerMetadata.js +1 -1
- package/esm/utils/ShakerMetadata.js.map +1 -1
- package/esm/utils/{addIdentifierToLinariaPreval.js → addIdentifierToWywPreval.js} +10 -10
- package/esm/utils/addIdentifierToWywPreval.js.map +1 -0
- package/esm/utils/collectExportsAndImports.js +141 -53
- package/esm/utils/collectExportsAndImports.js.map +1 -1
- package/esm/utils/collectTemplateDependencies.js +2 -2
- package/esm/utils/collectTemplateDependencies.js.map +1 -1
- package/esm/utils/getTagProcessor.js +1 -1
- package/esm/utils/getTagProcessor.js.map +1 -1
- package/esm/utils/hasWywPreval.js +7 -0
- package/esm/utils/hasWywPreval.js.map +1 -0
- package/lib/index.js +36 -4
- package/lib/index.js.map +1 -1
- package/lib/options/loadBabelOptions.js +1 -1
- package/lib/options/loadBabelOptions.js.map +1 -1
- package/lib/plugins/babel-transform.js +2 -2
- package/lib/plugins/babel-transform.js.map +1 -1
- package/lib/plugins/collector.js +4 -4
- package/lib/plugins/collector.js.map +1 -1
- package/lib/plugins/preeval.js +11 -11
- package/lib/plugins/preeval.js.map +1 -1
- package/lib/plugins/shaker.js +5 -5
- package/lib/plugins/shaker.js.map +1 -1
- package/lib/shaker.js +2 -2
- package/lib/shaker.js.map +1 -1
- package/lib/transform/Entrypoint.helpers.js +1 -2
- package/lib/transform/Entrypoint.helpers.js.map +1 -1
- package/lib/transform/Entrypoint.js +4 -4
- package/lib/transform/Entrypoint.js.map +1 -1
- package/lib/transform/generators/collect.js +1 -1
- package/lib/transform/generators/collect.js.map +1 -1
- package/lib/transform/generators/evalFile.js +6 -6
- package/lib/transform/generators/evalFile.js.map +1 -1
- package/lib/transform/generators/extract.js +18 -14
- package/lib/transform/generators/extract.js.map +1 -1
- package/lib/transform/generators/transform.js +2 -2
- package/lib/transform/generators/transform.js.map +1 -1
- package/lib/transform/generators/workflow.js +3 -3
- package/lib/transform/generators/workflow.js.map +1 -1
- package/lib/transform/helpers/{loadLinariaOptions.js → loadWywOptions.js} +6 -6
- package/lib/transform/helpers/loadWywOptions.js.map +1 -0
- package/lib/transform/helpers/withDefaultServices.js +2 -2
- package/lib/transform/helpers/withDefaultServices.js.map +1 -1
- package/lib/transform.js +11 -10
- package/lib/transform.js.map +1 -1
- package/lib/types.js.map +1 -1
- package/lib/utils/ShakerMetadata.js +1 -1
- package/lib/utils/ShakerMetadata.js.map +1 -1
- package/lib/utils/{addIdentifierToLinariaPreval.js → addIdentifierToWywPreval.js} +12 -12
- package/lib/utils/addIdentifierToWywPreval.js.map +1 -0
- package/lib/utils/collectExportsAndImports.js +141 -53
- package/lib/utils/collectExportsAndImports.js.map +1 -1
- package/lib/utils/collectTemplateDependencies.js +2 -2
- package/lib/utils/collectTemplateDependencies.js.map +1 -1
- package/lib/utils/getTagProcessor.js +2 -2
- package/lib/utils/getTagProcessor.js.map +1 -1
- package/lib/utils/hasWywPreval.js +13 -0
- package/lib/utils/hasWywPreval.js.map +1 -0
- package/lib/vm/createVmContext.js +2 -2
- package/lib/vm/createVmContext.js.map +1 -1
- package/package.json +25 -21
- package/types/index.d.ts +6 -2
- package/types/index.js +11 -3
- package/types/options/loadBabelOptions.js +1 -1
- package/types/plugins/babel-transform.js +2 -2
- package/types/plugins/collector.js +4 -4
- package/types/plugins/preeval.js +11 -11
- package/types/plugins/shaker.js +5 -5
- package/types/shaker.js +2 -2
- package/types/transform/Entrypoint.d.ts +1 -1
- package/types/transform/Entrypoint.helpers.js +3 -3
- package/types/transform/Entrypoint.js +4 -4
- package/types/transform/generators/collect.js +1 -1
- package/types/transform/generators/evalFile.js +7 -7
- package/types/transform/generators/extract.js +21 -12
- package/types/transform/generators/transform.js +2 -4
- package/types/transform/generators/workflow.js +3 -3
- package/types/transform/helpers/{loadLinariaOptions.d.ts → loadWywOptions.d.ts} +1 -1
- package/types/transform/helpers/{loadLinariaOptions.js → loadWywOptions.js} +19 -19
- package/types/transform.d.ts +7 -6
- package/types/transform.js +11 -10
- package/types/types.d.ts +1 -1
- package/types/utils/ShakerMetadata.d.ts +1 -1
- package/types/utils/ShakerMetadata.js +1 -1
- package/types/utils/addIdentifierToWywPreval.d.ts +4 -0
- package/types/utils/{addIdentifierToLinariaPreval.js → addIdentifierToWywPreval.js} +12 -12
- package/types/utils/collectExportsAndImports.js +157 -58
- package/types/utils/collectTemplateDependencies.d.ts +1 -1
- package/types/utils/collectTemplateDependencies.js +2 -2
- package/types/utils/getTagProcessor.js +2 -2
- package/types/utils/hasWywPreval.d.ts +4 -0
- package/types/utils/{hasLinariaPreval.js → hasWywPreval.js} +3 -3
- package/esm/transform/helpers/loadLinariaOptions.js.map +0 -1
- package/esm/utils/addIdentifierToLinariaPreval.js.map +0 -1
- package/esm/utils/findPackageJSON.js +0 -22
- package/esm/utils/findPackageJSON.js.map +0 -1
- package/esm/utils/hasLinariaPreval.js +0 -7
- package/esm/utils/hasLinariaPreval.js.map +0 -1
- package/lib/transform/helpers/loadLinariaOptions.js.map +0 -1
- package/lib/utils/addIdentifierToLinariaPreval.js.map +0 -1
- package/lib/utils/findPackageJSON.js +0 -29
- package/lib/utils/findPackageJSON.js.map +0 -1
- package/lib/utils/hasLinariaPreval.js +0 -13
- package/lib/utils/hasLinariaPreval.js.map +0 -1
- package/types/utils/addIdentifierToLinariaPreval.d.ts +0 -4
- package/types/utils/findPackageJSON.d.ts +0 -1
- package/types/utils/findPackageJSON.js +0 -29
- package/types/utils/hasLinariaPreval.d.ts +0 -4
|
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.evalFile = void 0;
|
|
7
7
|
const evaluators_1 = __importDefault(require("../../evaluators"));
|
|
8
|
-
const
|
|
8
|
+
const hasWywPreval_1 = __importDefault(require("../../utils/hasWywPreval"));
|
|
9
9
|
const UnprocessedEntrypointError_1 = require("../actions/UnprocessedEntrypointError");
|
|
10
10
|
const wrap = (fn) => {
|
|
11
11
|
try {
|
|
@@ -23,7 +23,7 @@ const wrap = (fn) => {
|
|
|
23
23
|
function* evalFile() {
|
|
24
24
|
const { entrypoint } = this;
|
|
25
25
|
const { log } = entrypoint;
|
|
26
|
-
log(`>> evaluate
|
|
26
|
+
log(`>> evaluate __wywPreval`);
|
|
27
27
|
let evaluated;
|
|
28
28
|
while (evaluated === undefined) {
|
|
29
29
|
try {
|
|
@@ -39,18 +39,18 @@ function* evalFile() {
|
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
|
-
const
|
|
43
|
-
? evaluated.value.
|
|
42
|
+
const wywPreval = (0, hasWywPreval_1.default)(evaluated.value)
|
|
43
|
+
? evaluated.value.__wywPreval
|
|
44
44
|
: undefined;
|
|
45
|
-
if (!
|
|
45
|
+
if (!wywPreval) {
|
|
46
46
|
return null;
|
|
47
47
|
}
|
|
48
48
|
const valueCache = new Map();
|
|
49
|
-
Object.entries(
|
|
49
|
+
Object.entries(wywPreval).forEach(([key, lazyValue]) => {
|
|
50
50
|
const value = wrap(lazyValue);
|
|
51
51
|
valueCache.set(key, value);
|
|
52
52
|
});
|
|
53
|
-
log(`<< evaluated
|
|
53
|
+
log(`<< evaluated __wywPreval %O`, valueCache);
|
|
54
54
|
return [valueCache, evaluated.dependencies];
|
|
55
55
|
}
|
|
56
56
|
exports.evalFile = evalFile;
|
|
@@ -6,8 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.extract = exports.transformUrl = void 0;
|
|
7
7
|
const path_1 = __importDefault(require("path"));
|
|
8
8
|
const source_map_1 = require("source-map");
|
|
9
|
-
const stylis_1 =
|
|
10
|
-
const STYLIS_DECLARATION = 1;
|
|
9
|
+
const stylis_1 = require("stylis");
|
|
11
10
|
const posixSep = path_1.default.posix.sep;
|
|
12
11
|
function transformUrl(url, outputFilename, sourceFilename, platformPath = path_1.default) {
|
|
13
12
|
// Replace asset path with new path relative to the output CSS
|
|
@@ -20,6 +19,25 @@ function transformUrl(url, outputFilename, sourceFilename, platformPath = path_1
|
|
|
20
19
|
return relative.split(platformPath.sep).join(posixSep);
|
|
21
20
|
}
|
|
22
21
|
exports.transformUrl = transformUrl;
|
|
22
|
+
function createStylisPreprocessor(options) {
|
|
23
|
+
function stylisPreprocess(selector, text) {
|
|
24
|
+
return (0, stylis_1.serialize)((0, stylis_1.compile)(`${selector} {${text}}\n`), (0, stylis_1.middleware)([
|
|
25
|
+
(element) => {
|
|
26
|
+
const { outputFilename } = options;
|
|
27
|
+
if (element.type === 'decl' && outputFilename) {
|
|
28
|
+
// When writing to a file, we need to adjust the relative paths inside url(..) expressions.
|
|
29
|
+
// It'll allow css-loader to resolve an imported asset properly.
|
|
30
|
+
// eslint-disable-next-line no-param-reassign
|
|
31
|
+
element.return = element.value.replace(/\b(url\((["']?))(\.[^)]+?)(\2\))/g, (match, p1, p2, p3, p4) => p1 + transformUrl(p3, outputFilename, options.filename) + p4);
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
stylis_1.namespace,
|
|
35
|
+
stylis_1.prefixer,
|
|
36
|
+
stylis_1.stringify,
|
|
37
|
+
]));
|
|
38
|
+
}
|
|
39
|
+
return stylisPreprocess;
|
|
40
|
+
}
|
|
23
41
|
function extractCssFromAst(rules, originalCode, options) {
|
|
24
42
|
const mappings = [];
|
|
25
43
|
let cssText = '';
|
|
@@ -35,16 +53,7 @@ function extractCssFromAst(rules, originalCode, options) {
|
|
|
35
53
|
break;
|
|
36
54
|
case 'stylis':
|
|
37
55
|
default:
|
|
38
|
-
|
|
39
|
-
const { outputFilename } = options;
|
|
40
|
-
if (context === STYLIS_DECLARATION && outputFilename) {
|
|
41
|
-
// When writing to a file, we need to adjust the relative paths inside url(..) expressions
|
|
42
|
-
// It'll allow css-loader to resolve an imported asset properly
|
|
43
|
-
return decl.replace(/\b(url\((["']?))(\.[^)]+?)(\2\))/g, (match, p1, p2, p3, p4) => p1 + transformUrl(p3, outputFilename, options.filename) + p4);
|
|
44
|
-
}
|
|
45
|
-
return decl;
|
|
46
|
-
});
|
|
47
|
-
preprocessor = stylis_1.default;
|
|
56
|
+
preprocessor = createStylisPreprocessor(options);
|
|
48
57
|
}
|
|
49
58
|
}
|
|
50
59
|
Object.keys(rules).forEach((selector, index) => {
|
|
@@ -22,7 +22,7 @@ function runPreevalStage(babel, evalConfig, pluginOptions, code, originalAst, ev
|
|
|
22
22
|
];
|
|
23
23
|
const transformConfig = (0, buildOptions_1.buildOptions)({
|
|
24
24
|
...evalConfig,
|
|
25
|
-
envName: '
|
|
25
|
+
envName: 'wyw-in-js',
|
|
26
26
|
plugins,
|
|
27
27
|
});
|
|
28
28
|
const result = babel.transformFromAstSync(originalAst, code, transformConfig);
|
|
@@ -42,9 +42,7 @@ const prepareCode = (services, item, originalAst) => {
|
|
|
42
42
|
const { pluginOptions } = options;
|
|
43
43
|
const preevalStageResult = eventEmitter.perf('transform:preeval', () => runPreevalStage(babel, evalConfig, pluginOptions, code, originalAst, eventEmitter));
|
|
44
44
|
const transformMetadata = (0, TransformMetadata_1.getTransformMetadata)(preevalStageResult.metadata);
|
|
45
|
-
if (only.length === 1 &&
|
|
46
|
-
only[0] === '__linariaPreval' &&
|
|
47
|
-
!transformMetadata) {
|
|
45
|
+
if (only.length === 1 && only[0] === '__wywPreval' && !transformMetadata) {
|
|
48
46
|
log('[evaluator:end] no metadata');
|
|
49
47
|
return [preevalStageResult.code, null, null];
|
|
50
48
|
}
|
|
@@ -29,10 +29,10 @@ function* workflow() {
|
|
|
29
29
|
}
|
|
30
30
|
const originalCode = entrypoint.loadedAndParsed.code ?? '';
|
|
31
31
|
// File is ignored or does not contain any tags. Return original code.
|
|
32
|
-
if (!entrypoint.
|
|
32
|
+
if (!entrypoint.hasWywMetadata()) {
|
|
33
33
|
if (entrypoint.generation === 1) {
|
|
34
|
-
// 1st generation here means that it's
|
|
35
|
-
// without
|
|
34
|
+
// 1st generation here means that it's __wywPreval entrypoint
|
|
35
|
+
// without __wywPreval, so we don't need it cached
|
|
36
36
|
cache.delete('entrypoints', entrypoint.name);
|
|
37
37
|
}
|
|
38
38
|
return {
|
|
@@ -3,4 +3,4 @@ import type { PluginOptions } from '../../types';
|
|
|
3
3
|
export type PartialOptions = Partial<Omit<PluginOptions, 'features'>> & {
|
|
4
4
|
features?: Partial<FeatureFlags>;
|
|
5
5
|
};
|
|
6
|
-
export declare function
|
|
6
|
+
export declare function loadWywOptions(overrides?: PartialOptions): StrictOptions;
|
|
@@ -3,30 +3,30 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.loadWywOptions = void 0;
|
|
7
7
|
const cosmiconfig_1 = require("cosmiconfig");
|
|
8
8
|
const shaker_1 = __importDefault(require("../../shaker"));
|
|
9
9
|
const searchPlaces = [
|
|
10
|
-
`.
|
|
11
|
-
`.
|
|
12
|
-
`.
|
|
13
|
-
`.
|
|
14
|
-
`.
|
|
15
|
-
`.
|
|
16
|
-
`.config/
|
|
17
|
-
`.config/
|
|
18
|
-
`.config/
|
|
19
|
-
`.config/
|
|
20
|
-
`.config/
|
|
21
|
-
`.config/
|
|
22
|
-
`
|
|
23
|
-
`
|
|
10
|
+
`.wyw-in-jsrc`,
|
|
11
|
+
`.wyw-in-jsrc.json`,
|
|
12
|
+
`.wyw-in-jsrc.yaml`,
|
|
13
|
+
`.wyw-in-jsrc.yml`,
|
|
14
|
+
`.wyw-in-jsrc.js`,
|
|
15
|
+
`.wyw-in-jsrc.cjs`,
|
|
16
|
+
`.config/wyw-in-jsrc`,
|
|
17
|
+
`.config/wyw-in-jsrc.json`,
|
|
18
|
+
`.config/wyw-in-jsrc.yaml`,
|
|
19
|
+
`.config/wyw-in-jsrc.yml`,
|
|
20
|
+
`.config/wyw-in-jsrc.js`,
|
|
21
|
+
`.config/wyw-in-jsrc.cjs`,
|
|
22
|
+
`wyw-in-js.config.js`,
|
|
23
|
+
`wyw-in-js.config.cjs`,
|
|
24
24
|
];
|
|
25
|
-
const explorerSync = (0, cosmiconfig_1.cosmiconfigSync)('
|
|
25
|
+
const explorerSync = (0, cosmiconfig_1.cosmiconfigSync)('wyw-in-js', { searchPlaces });
|
|
26
26
|
const cache = new WeakMap();
|
|
27
27
|
const defaultOverrides = {};
|
|
28
28
|
const nodeModulesRegExp = /[\\/]node_modules[\\/]/;
|
|
29
|
-
function
|
|
29
|
+
function loadWywOptions(overrides = defaultOverrides) {
|
|
30
30
|
if (cache.has(overrides)) {
|
|
31
31
|
return cache.get(overrides);
|
|
32
32
|
}
|
|
@@ -65,7 +65,7 @@ function loadLinariaOptions(overrides = defaultOverrides) {
|
|
|
65
65
|
return false;
|
|
66
66
|
}
|
|
67
67
|
// If a file contains `export` or `import` keywords, we assume it's an ES-module
|
|
68
|
-
return /(
|
|
68
|
+
return /(?:^|\*\/|;|})\s*(?:export|import)[\s{]/m.test(code);
|
|
69
69
|
},
|
|
70
70
|
action: shaker_1.default,
|
|
71
71
|
},
|
|
@@ -83,4 +83,4 @@ function loadLinariaOptions(overrides = defaultOverrides) {
|
|
|
83
83
|
cache.set(overrides, options);
|
|
84
84
|
return options;
|
|
85
85
|
}
|
|
86
|
-
exports.
|
|
86
|
+
exports.loadWywOptions = loadWywOptions;
|
package/types/transform.d.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* This file exposes transform
|
|
2
|
+
* This file exposes sync and async transform functions that:
|
|
3
3
|
* - parse the passed code to AST
|
|
4
|
-
* -
|
|
5
|
-
* -
|
|
6
|
-
* -
|
|
7
|
-
* -
|
|
4
|
+
* - builds a dependency graph for the file
|
|
5
|
+
* - shakes each dependency and removes unused code
|
|
6
|
+
* - runs generated code in a sandbox
|
|
7
|
+
* - collects artifacts
|
|
8
|
+
* - returns transformed code (without WYW template literals), generated CSS, source maps and babel metadata from transform step.
|
|
8
9
|
*/
|
|
9
|
-
import type { PartialOptions } from './transform/helpers/
|
|
10
|
+
import type { PartialOptions } from './transform/helpers/loadWywOptions';
|
|
10
11
|
import type { Handlers, Services } from './transform/types';
|
|
11
12
|
import type { Result } from './types';
|
|
12
13
|
type PartialServices = Partial<Omit<Services, 'options'>> & {
|
package/types/transform.js
CHANGED
|
@@ -1,25 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
* This file exposes transform
|
|
3
|
+
* This file exposes sync and async transform functions that:
|
|
4
4
|
* - parse the passed code to AST
|
|
5
|
-
* -
|
|
6
|
-
* -
|
|
7
|
-
* -
|
|
8
|
-
* -
|
|
5
|
+
* - builds a dependency graph for the file
|
|
6
|
+
* - shakes each dependency and removes unused code
|
|
7
|
+
* - runs generated code in a sandbox
|
|
8
|
+
* - collects artifacts
|
|
9
|
+
* - returns transformed code (without WYW template literals), generated CSS, source maps and babel metadata from transform step.
|
|
9
10
|
*/
|
|
10
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
12
|
exports.transform = exports.transformSync = void 0;
|
|
12
13
|
const shared_1 = require("@wyw-in-js/shared");
|
|
14
|
+
const loadWywOptions_1 = require("./transform/helpers/loadWywOptions");
|
|
13
15
|
const cache_1 = require("./cache");
|
|
14
16
|
const Entrypoint_1 = require("./transform/Entrypoint");
|
|
15
17
|
const actionRunner_1 = require("./transform/actions/actionRunner");
|
|
16
18
|
const generators_1 = require("./transform/generators");
|
|
17
19
|
const resolveImports_1 = require("./transform/generators/resolveImports");
|
|
18
|
-
const loadLinariaOptions_1 = require("./transform/helpers/loadLinariaOptions");
|
|
19
20
|
const withDefaultServices_1 = require("./transform/helpers/withDefaultServices");
|
|
20
21
|
function transformSync(partialServices, originalCode, syncResolve, customHandlers = {}) {
|
|
21
22
|
const { options } = partialServices;
|
|
22
|
-
const pluginOptions = (0,
|
|
23
|
+
const pluginOptions = (0, loadWywOptions_1.loadWywOptions)(options.pluginOptions);
|
|
23
24
|
const services = (0, withDefaultServices_1.withDefaultServices)({
|
|
24
25
|
...partialServices,
|
|
25
26
|
options: {
|
|
@@ -31,7 +32,7 @@ function transformSync(partialServices, originalCode, syncResolve, customHandler
|
|
|
31
32
|
// If global cache is disabled, we need to create a new cache for each file
|
|
32
33
|
services.cache = new cache_1.TransformCacheCollection();
|
|
33
34
|
}
|
|
34
|
-
const entrypoint = Entrypoint_1.Entrypoint.createRoot(services, options.filename, ['
|
|
35
|
+
const entrypoint = Entrypoint_1.Entrypoint.createRoot(services, options.filename, ['__wywPreval'], originalCode);
|
|
35
36
|
if (entrypoint.ignored) {
|
|
36
37
|
return {
|
|
37
38
|
code: originalCode,
|
|
@@ -66,7 +67,7 @@ function transformSync(partialServices, originalCode, syncResolve, customHandler
|
|
|
66
67
|
exports.transformSync = transformSync;
|
|
67
68
|
async function transform(partialServices, originalCode, asyncResolve, customHandlers = {}) {
|
|
68
69
|
const { options } = partialServices;
|
|
69
|
-
const pluginOptions = (0,
|
|
70
|
+
const pluginOptions = (0, loadWywOptions_1.loadWywOptions)(options.pluginOptions);
|
|
70
71
|
const services = (0, withDefaultServices_1.withDefaultServices)({
|
|
71
72
|
...partialServices,
|
|
72
73
|
options: {
|
|
@@ -86,7 +87,7 @@ async function transform(partialServices, originalCode, asyncResolve, customHand
|
|
|
86
87
|
* but the "only" option has changed, the file will be re-processed using
|
|
87
88
|
* the combined "only" option.
|
|
88
89
|
*/
|
|
89
|
-
const entrypoint = Entrypoint_1.Entrypoint.createRoot(services, options.filename, ['
|
|
90
|
+
const entrypoint = Entrypoint_1.Entrypoint.createRoot(services, options.filename, ['__wywPreval'], originalCode);
|
|
90
91
|
if (entrypoint.ignored) {
|
|
91
92
|
return {
|
|
92
93
|
code: originalCode,
|
package/types/types.d.ts
CHANGED
|
@@ -2,6 +2,6 @@ export interface IShakerMetadata {
|
|
|
2
2
|
imports: Map<string, string[]>;
|
|
3
3
|
}
|
|
4
4
|
export interface IMetadata {
|
|
5
|
-
|
|
5
|
+
wywEvaluator: IShakerMetadata;
|
|
6
6
|
}
|
|
7
7
|
export declare const hasShakerMetadata: (metadata: object | undefined) => metadata is IMetadata;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.hasShakerMetadata = void 0;
|
|
4
|
-
const hasShakerMetadata = (metadata) => metadata !== undefined && '
|
|
4
|
+
const hasShakerMetadata = (metadata) => metadata !== undefined && 'wywEvaluator' in metadata;
|
|
5
5
|
exports.hasShakerMetadata = hasShakerMetadata;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { NodePath, Scope } from '@babel/traverse';
|
|
2
|
+
import type { ObjectExpression } from '@babel/types';
|
|
3
|
+
export declare function getOrAddWywPreval(scope: Scope): NodePath<ObjectExpression>;
|
|
4
|
+
export declare function addIdentifierToWywPreval(scope: Scope, name: string): void;
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.addIdentifierToWywPreval = exports.getOrAddWywPreval = void 0;
|
|
4
4
|
const createId_1 = require("./createId");
|
|
5
5
|
const scopeHelpers_1 = require("./scopeHelpers");
|
|
6
|
-
function
|
|
6
|
+
function getOrAddWywPreval(scope) {
|
|
7
7
|
const rootScope = scope.getProgramParent();
|
|
8
8
|
const programPath = rootScope.path;
|
|
9
|
-
let object = programPath.getData('
|
|
9
|
+
let object = programPath.getData('__wywPreval');
|
|
10
10
|
if (object) {
|
|
11
11
|
return object;
|
|
12
12
|
}
|
|
13
13
|
if (programPath.node.sourceType === 'script') {
|
|
14
|
-
// CJS exports.
|
|
14
|
+
// CJS exports.__wywPreval = {};
|
|
15
15
|
const prevalExport = {
|
|
16
16
|
expression: {
|
|
17
17
|
type: 'AssignmentExpression',
|
|
@@ -19,7 +19,7 @@ function getOrAddLinariaPreval(scope) {
|
|
|
19
19
|
left: {
|
|
20
20
|
computed: false,
|
|
21
21
|
object: (0, createId_1.createId)('exports'),
|
|
22
|
-
property: (0, createId_1.createId)('
|
|
22
|
+
property: (0, createId_1.createId)('__wywPreval'),
|
|
23
23
|
type: 'MemberExpression',
|
|
24
24
|
},
|
|
25
25
|
right: {
|
|
@@ -33,12 +33,12 @@ function getOrAddLinariaPreval(scope) {
|
|
|
33
33
|
object = inserted.get('expression.right');
|
|
34
34
|
}
|
|
35
35
|
else {
|
|
36
|
-
// ESM export const
|
|
36
|
+
// ESM export const __wywPreval = {};
|
|
37
37
|
const prevalExport = {
|
|
38
38
|
declaration: {
|
|
39
39
|
declarations: [
|
|
40
40
|
{
|
|
41
|
-
id: (0, createId_1.createId)('
|
|
41
|
+
id: (0, createId_1.createId)('__wywPreval'),
|
|
42
42
|
init: {
|
|
43
43
|
properties: [],
|
|
44
44
|
type: 'ObjectExpression',
|
|
@@ -55,13 +55,13 @@ function getOrAddLinariaPreval(scope) {
|
|
|
55
55
|
const [inserted] = programPath.pushContainer('body', [prevalExport]);
|
|
56
56
|
object = inserted.get('declaration.declarations.0.init');
|
|
57
57
|
}
|
|
58
|
-
programPath.setData('
|
|
58
|
+
programPath.setData('__wywPreval', object);
|
|
59
59
|
return object;
|
|
60
60
|
}
|
|
61
|
-
exports.
|
|
62
|
-
function
|
|
61
|
+
exports.getOrAddWywPreval = getOrAddWywPreval;
|
|
62
|
+
function addIdentifierToWywPreval(scope, name) {
|
|
63
63
|
const rootScope = scope.getProgramParent();
|
|
64
|
-
const object =
|
|
64
|
+
const object = getOrAddWywPreval(rootScope);
|
|
65
65
|
const newProperty = {
|
|
66
66
|
type: 'ObjectProperty',
|
|
67
67
|
key: (0, createId_1.createId)(name),
|
|
@@ -72,4 +72,4 @@ function addIdentifierToLinariaPreval(scope, name) {
|
|
|
72
72
|
const [inserted] = object.pushContainer('properties', [newProperty]);
|
|
73
73
|
(0, scopeHelpers_1.reference)(inserted.get('value'));
|
|
74
74
|
}
|
|
75
|
-
exports.
|
|
75
|
+
exports.addIdentifierToWywPreval = addIdentifierToWywPreval;
|