@rollipop/jest-preset 1.0.0-alpha.28 → 1.0.0-alpha.30
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/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/mock.d.ts +15 -0
- package/dist/mock.js +40 -0
- package/dist/transformer-B9RYZvsj.js +144 -0
- package/dist/transformer-Cn7TWwgX.d.ts +49 -0
- package/dist/transformer.d.ts +2 -26
- package/dist/transformer.js +1 -1
- package/jest-preset.js +16 -5
- package/package.json +16 -6
- package/dist/transformer-Bv1COwca.js +0 -108
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { i as createTransformer, r as TransformerOptions } from "./transformer-Cn7TWwgX.js";
|
|
2
2
|
export { type TransformerOptions, createTransformer };
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_transformer = require("./transformer-
|
|
2
|
+
const require_transformer = require("./transformer-B9RYZvsj.js");
|
|
3
3
|
exports.createTransformer = require_transformer.createTransformer;
|
package/dist/mock.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
//#region src/mock.d.ts
|
|
2
|
+
export type GlobImportPattern = string | string[];
|
|
3
|
+
export type GlobImportOptions = Record<string, unknown>;
|
|
4
|
+
export type GlobImportResult = Record<string, unknown>;
|
|
5
|
+
export interface GlobImportContext {
|
|
6
|
+
importer: string;
|
|
7
|
+
pattern: GlobImportPattern;
|
|
8
|
+
options?: GlobImportOptions;
|
|
9
|
+
}
|
|
10
|
+
export type GlobImportMock = (context: GlobImportContext) => GlobImportResult;
|
|
11
|
+
export declare function createGlobImport(importer: string): (pattern: GlobImportPattern, options?: GlobImportOptions) => GlobImportResult;
|
|
12
|
+
export declare function mockGlobImport(implementation: GlobImportMock): void;
|
|
13
|
+
export declare function resetGlobImport(): void;
|
|
14
|
+
export declare function resetRollipopJestPresetMocks(): void;
|
|
15
|
+
//#endregion
|
package/dist/mock.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/mock.ts
|
|
3
|
+
let globImportMock;
|
|
4
|
+
function createGlobImport(importer) {
|
|
5
|
+
return function globImport(pattern, options) {
|
|
6
|
+
if (globImportMock == null) throw new Error([
|
|
7
|
+
"@rollipop/jest-preset: Glob import is a bundler-only feature.",
|
|
8
|
+
`Importer: ${importer}`,
|
|
9
|
+
`Pattern: ${formatValue(pattern)}`,
|
|
10
|
+
"",
|
|
11
|
+
"Mock it in Jest with `mockGlobImport()` from \"@rollipop/jest-preset/mock\"."
|
|
12
|
+
].join("\n"));
|
|
13
|
+
return globImportMock({
|
|
14
|
+
importer,
|
|
15
|
+
pattern,
|
|
16
|
+
options
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
function mockGlobImport(implementation) {
|
|
21
|
+
globImportMock = implementation;
|
|
22
|
+
}
|
|
23
|
+
function resetGlobImport() {
|
|
24
|
+
globImportMock = void 0;
|
|
25
|
+
}
|
|
26
|
+
function resetRollipopJestPresetMocks() {
|
|
27
|
+
resetGlobImport();
|
|
28
|
+
}
|
|
29
|
+
function formatValue(value) {
|
|
30
|
+
try {
|
|
31
|
+
return JSON.stringify(value);
|
|
32
|
+
} catch {
|
|
33
|
+
return String(value);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
//#endregion
|
|
37
|
+
exports.createGlobImport = createGlobImport;
|
|
38
|
+
exports.mockGlobImport = mockGlobImport;
|
|
39
|
+
exports.resetGlobImport = resetGlobImport;
|
|
40
|
+
exports.resetRollipopJestPresetMocks = resetRollipopJestPresetMocks;
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
let node_crypto = require("node:crypto");
|
|
2
|
+
let node_module = require("node:module");
|
|
3
|
+
let rollipop = require("rollipop");
|
|
4
|
+
//#region src/env.ts
|
|
5
|
+
function defineEnvFromObject(env) {
|
|
6
|
+
return Object.fromEntries(Object.entries(env).map(([key, value]) => [`import.meta.env.${key}`, asLiteral(value)]));
|
|
7
|
+
}
|
|
8
|
+
function asLiteral(value) {
|
|
9
|
+
return JSON.stringify(value);
|
|
10
|
+
}
|
|
11
|
+
//#endregion
|
|
12
|
+
//#region src/runtime.ts
|
|
13
|
+
const GLOB_IMPORT_HELPERS = {
|
|
14
|
+
cjs: `require('@rollipop/jest-preset/mock').createGlobImport(__filename);`,
|
|
15
|
+
esm: `import.meta.jest.requireActual('@rollipop/jest-preset/mock').createGlobImport(import.meta.jest.requireActual("node:url").fileURLToPath(import.meta.url));`
|
|
16
|
+
};
|
|
17
|
+
//#endregion
|
|
18
|
+
//#region src/utils.ts
|
|
19
|
+
function resolveMode(mode = process.env.NODE_ENV) {
|
|
20
|
+
switch (mode) {
|
|
21
|
+
case "development":
|
|
22
|
+
case "production": return mode;
|
|
23
|
+
default: return "development";
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function packageVersion(packageJsonPath) {
|
|
27
|
+
try {
|
|
28
|
+
return require(packageJsonPath).version;
|
|
29
|
+
} catch {
|
|
30
|
+
return "unknown";
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
function createContext(options) {
|
|
34
|
+
const mode = resolveMode(options.mode);
|
|
35
|
+
const env = (0, rollipop.loadEnv)({
|
|
36
|
+
envDir: options.envDir ?? options.root ?? process.cwd(),
|
|
37
|
+
envFile: options.envFile ?? rollipop.Constants.DEFAULT_ENV_FILE,
|
|
38
|
+
envPrefix: options.envPrefix ?? rollipop.Constants.DEFAULT_ENV_PREFIX,
|
|
39
|
+
mode
|
|
40
|
+
});
|
|
41
|
+
const { enabled: canInstrument = false, ...instrumentOptions } = options.experimental?.customCoverageInstrumentation ?? {};
|
|
42
|
+
const nativeRequire = (0, node_module.createRequire)(require.resolve("rollipop/package.json"));
|
|
43
|
+
const optionsHash = (0, node_crypto.createHash)("sha1").update(JSON.stringify({
|
|
44
|
+
version: packageVersion("@rollipop/jest-preset/package.json"),
|
|
45
|
+
nativeVersion: packageVersion(nativeRequire.resolve("@rollipop/rolldown/package.json")),
|
|
46
|
+
cwd: process.cwd(),
|
|
47
|
+
mode,
|
|
48
|
+
env,
|
|
49
|
+
options
|
|
50
|
+
})).digest("hex");
|
|
51
|
+
return {
|
|
52
|
+
options,
|
|
53
|
+
mode,
|
|
54
|
+
globals: {
|
|
55
|
+
"import.meta.hot": "undefined",
|
|
56
|
+
"import.meta.env": JSON.stringify({}),
|
|
57
|
+
...defineEnvFromObject(env),
|
|
58
|
+
...defineEnvFromObject({ MODE: mode })
|
|
59
|
+
},
|
|
60
|
+
canInstrument,
|
|
61
|
+
instrumentOptions,
|
|
62
|
+
optionsHash,
|
|
63
|
+
pipelines: /* @__PURE__ */ new Map()
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
function getCoveragePlugin(context) {
|
|
67
|
+
return context.coveragePlugin ??= {
|
|
68
|
+
path: require.resolve("swc-plugin-coverage-instrument"),
|
|
69
|
+
version: packageVersion("swc-plugin-coverage-instrument/package.json")
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
function getPipeline(context, jestOptions = {}) {
|
|
73
|
+
const esm = jestOptions.supportsStaticESM === true;
|
|
74
|
+
const instrument = context.canInstrument && jestOptions.instrument === true;
|
|
75
|
+
const key = Number(esm) * 2 + Number(instrument);
|
|
76
|
+
let pipeline = context.pipelines.get(key);
|
|
77
|
+
if (pipeline == null) {
|
|
78
|
+
const swc = {
|
|
79
|
+
globals: {
|
|
80
|
+
...context.globals,
|
|
81
|
+
"import.meta.glob": esm ? GLOB_IMPORT_HELPERS.esm : GLOB_IMPORT_HELPERS.cjs
|
|
82
|
+
},
|
|
83
|
+
react: {
|
|
84
|
+
development: context.mode === "development",
|
|
85
|
+
runtime: "Automatic"
|
|
86
|
+
},
|
|
87
|
+
module: { type: esm ? "unambiguous" : "commonjs" },
|
|
88
|
+
plugins: instrument ? [[getCoveragePlugin(context).path, context.instrumentOptions]] : void 0
|
|
89
|
+
};
|
|
90
|
+
const config = {
|
|
91
|
+
envName: context.mode,
|
|
92
|
+
runtimeTarget: context.options.runtimeTarget,
|
|
93
|
+
swc: {
|
|
94
|
+
...swc,
|
|
95
|
+
jest: true
|
|
96
|
+
},
|
|
97
|
+
flow: context.options.flow,
|
|
98
|
+
worklets: context.options.worklets
|
|
99
|
+
};
|
|
100
|
+
pipeline = new rollipop.rolldownExperimental.RollipopReactNativeTransformer(config);
|
|
101
|
+
context.pipelines.set(key, pipeline);
|
|
102
|
+
}
|
|
103
|
+
return pipeline;
|
|
104
|
+
}
|
|
105
|
+
function getCacheKey(context, sourceText, sourcePath, jestOptions = {}) {
|
|
106
|
+
return (0, node_crypto.createHash)("sha1").update(context.optionsHash).update("\0").update(JSON.stringify({
|
|
107
|
+
configString: jestOptions.configString ?? "",
|
|
108
|
+
instrument: jestOptions.instrument === true,
|
|
109
|
+
supportsStaticESM: jestOptions.supportsStaticESM === true,
|
|
110
|
+
coveragePluginVersion: context.canInstrument && jestOptions.instrument === true ? getCoveragePlugin(context).version : void 0
|
|
111
|
+
})).update("\0").update(sourcePath).update("\0").update(sourceText).digest("hex");
|
|
112
|
+
}
|
|
113
|
+
//#endregion
|
|
114
|
+
//#region src/transformer.ts
|
|
115
|
+
function createTransformer(options = {}) {
|
|
116
|
+
const context = createContext(options);
|
|
117
|
+
return {
|
|
118
|
+
canInstrument: context.canInstrument,
|
|
119
|
+
process(sourceText, sourcePath, jestOptions) {
|
|
120
|
+
const result = getPipeline(context, jestOptions).transformSync(sourcePath, sourceText);
|
|
121
|
+
return {
|
|
122
|
+
code: result.code,
|
|
123
|
+
...result.map != null ? { map: result.map } : null
|
|
124
|
+
};
|
|
125
|
+
},
|
|
126
|
+
async processAsync(sourceText, sourcePath, jestOptions) {
|
|
127
|
+
const result = await getPipeline(context, jestOptions).transform(sourcePath, sourceText);
|
|
128
|
+
return {
|
|
129
|
+
code: result.code,
|
|
130
|
+
...result.map != null ? { map: result.map } : null
|
|
131
|
+
};
|
|
132
|
+
},
|
|
133
|
+
getCacheKey(sourceText, sourcePath, jestOptions) {
|
|
134
|
+
return getCacheKey(context, sourceText, sourcePath, jestOptions);
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
//#endregion
|
|
139
|
+
Object.defineProperty(exports, "createTransformer", {
|
|
140
|
+
enumerable: true,
|
|
141
|
+
get: function() {
|
|
142
|
+
return createTransformer;
|
|
143
|
+
}
|
|
144
|
+
});
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { rolldownExperimental } from "rollipop";
|
|
2
|
+
//#region src/utils.d.ts
|
|
3
|
+
interface TransformOptions {
|
|
4
|
+
configString?: string;
|
|
5
|
+
instrument?: boolean;
|
|
6
|
+
supportsStaticESM?: boolean;
|
|
7
|
+
}
|
|
8
|
+
//#endregion
|
|
9
|
+
//#region src/transformer.d.ts
|
|
10
|
+
interface TransformerOptions {
|
|
11
|
+
mode?: 'development' | 'production';
|
|
12
|
+
root?: string;
|
|
13
|
+
runtimeTarget?: rolldownExperimental.RollipopReactNativeRuntimeTarget;
|
|
14
|
+
flow?: rolldownExperimental.RollipopReactNativeFlowConfig;
|
|
15
|
+
worklets?: rolldownExperimental.RollipopReactNativeWorkletsConfig;
|
|
16
|
+
envDir?: string;
|
|
17
|
+
envFile?: string;
|
|
18
|
+
envPrefix?: string;
|
|
19
|
+
experimental?: ExperimentalOptions;
|
|
20
|
+
}
|
|
21
|
+
interface ExperimentalOptions {
|
|
22
|
+
/** Native SWC coverage instrumentation, using the same options as `@swc/jest`. */
|
|
23
|
+
customCoverageInstrumentation?: CustomCoverageInstrumentationOptions;
|
|
24
|
+
}
|
|
25
|
+
interface CustomCoverageInstrumentationOptions {
|
|
26
|
+
/** Instrument only when Jest requests coverage. Defaults to `false`. */
|
|
27
|
+
enabled: boolean;
|
|
28
|
+
coverageVariable?: string;
|
|
29
|
+
compact?: boolean;
|
|
30
|
+
reportLogic?: boolean;
|
|
31
|
+
ignoreClassMethods?: string[];
|
|
32
|
+
instrumentLog?: {
|
|
33
|
+
level: string;
|
|
34
|
+
enableTrace: boolean;
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
interface JestTransformOutput {
|
|
38
|
+
code: string;
|
|
39
|
+
map?: string;
|
|
40
|
+
}
|
|
41
|
+
interface JestSyncTransformer {
|
|
42
|
+
canInstrument: boolean;
|
|
43
|
+
process(sourceText: string, sourcePath: string, options?: TransformOptions): JestTransformOutput;
|
|
44
|
+
processAsync(sourceText: string, sourcePath: string, options?: TransformOptions): Promise<JestTransformOutput>;
|
|
45
|
+
getCacheKey(sourceText: string, sourcePath: string, options?: TransformOptions): string;
|
|
46
|
+
}
|
|
47
|
+
declare function createTransformer(options?: TransformerOptions): JestSyncTransformer;
|
|
48
|
+
//#endregion
|
|
49
|
+
export { createTransformer as i, ExperimentalOptions as n, TransformerOptions as r, CustomCoverageInstrumentationOptions as t };
|
package/dist/transformer.d.ts
CHANGED
|
@@ -1,26 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
//#region src/transformer.d.ts
|
|
4
|
-
interface TransformerOptions {
|
|
5
|
-
mode?: 'development' | 'production';
|
|
6
|
-
root?: string;
|
|
7
|
-
runtimeTarget?: rolldownExperimental.RollipopReactNativeRuntimeTarget;
|
|
8
|
-
flow?: rolldownExperimental.RollipopReactNativeFlowConfig;
|
|
9
|
-
worklets?: rolldownExperimental.RollipopReactNativeWorkletsConfig;
|
|
10
|
-
envDir?: string;
|
|
11
|
-
envFile?: string;
|
|
12
|
-
envPrefix?: string;
|
|
13
|
-
}
|
|
14
|
-
interface JestTransformOutput {
|
|
15
|
-
code: string;
|
|
16
|
-
map?: string;
|
|
17
|
-
}
|
|
18
|
-
interface JestSyncTransformer {
|
|
19
|
-
canInstrument: false;
|
|
20
|
-
process(sourceText: string, sourcePath: string): JestTransformOutput;
|
|
21
|
-
processAsync(sourceText: string, sourcePath: string): Promise<JestTransformOutput>;
|
|
22
|
-
getCacheKey(sourceText: string, sourcePath: string): string;
|
|
23
|
-
}
|
|
24
|
-
declare function createTransformer(options?: TransformerOptions): JestSyncTransformer;
|
|
25
|
-
//#endregion
|
|
26
|
-
export { TransformerOptions, createTransformer };
|
|
1
|
+
import { i as createTransformer, n as ExperimentalOptions, r as TransformerOptions, t as CustomCoverageInstrumentationOptions } from "./transformer-Cn7TWwgX.js";
|
|
2
|
+
export { CustomCoverageInstrumentationOptions, ExperimentalOptions, TransformerOptions, createTransformer };
|
package/dist/transformer.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_transformer = require("./transformer-
|
|
2
|
+
const require_transformer = require("./transformer-B9RYZvsj.js");
|
|
3
3
|
exports.createTransformer = require_transformer.createTransformer;
|
package/jest-preset.js
CHANGED
|
@@ -1,15 +1,26 @@
|
|
|
1
1
|
const path = require('node:path');
|
|
2
2
|
|
|
3
|
+
const projectRoot = process.cwd();
|
|
4
|
+
|
|
5
|
+
function requireFromProjectRoot(id) {
|
|
6
|
+
return require(require.resolve(id, { paths: [projectRoot] }));
|
|
7
|
+
}
|
|
8
|
+
|
|
3
9
|
function loadBasePreset() {
|
|
4
|
-
let preset;
|
|
5
10
|
try {
|
|
6
|
-
|
|
7
|
-
|
|
11
|
+
return {
|
|
12
|
+
preset: requireFromProjectRoot('@react-native/jest-preset'),
|
|
13
|
+
setup: '@react-native/jest-preset/setup.js',
|
|
14
|
+
};
|
|
8
15
|
} catch {}
|
|
16
|
+
|
|
9
17
|
try {
|
|
10
|
-
|
|
11
|
-
|
|
18
|
+
return {
|
|
19
|
+
preset: requireFromProjectRoot('react-native/jest-preset'),
|
|
20
|
+
setup: 'react-native/jest/setup.js',
|
|
21
|
+
};
|
|
12
22
|
} catch {}
|
|
23
|
+
|
|
13
24
|
throw new Error(
|
|
14
25
|
'@rollipop/jest-preset: could not resolve a React Native jest preset. ' +
|
|
15
26
|
'Install either `@react-native/jest-preset` (RN >= 0.85) or `react-native` (RN <= 0.84).',
|
package/package.json
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rollipop/jest-preset",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
4
|
-
"stableVersion": "1.0.0-alpha.23",
|
|
3
|
+
"version": "1.0.0-alpha.30",
|
|
5
4
|
"homepage": "https://github.com/rollipop-dev/rollipop#readme",
|
|
6
5
|
"bugs": {
|
|
7
6
|
"url": "https://github.com/rollipop-dev/rollipop/issues"
|
|
@@ -28,24 +27,32 @@
|
|
|
28
27
|
"types": "./dist/transformer.d.ts",
|
|
29
28
|
"default": "./dist/transformer.js"
|
|
30
29
|
},
|
|
30
|
+
"./mock": {
|
|
31
|
+
"types": "./dist/mock.d.ts",
|
|
32
|
+
"default": "./dist/mock.js"
|
|
33
|
+
},
|
|
31
34
|
"./jest-preset": "./jest-preset.js",
|
|
32
35
|
"./package.json": "./package.json"
|
|
33
36
|
},
|
|
34
37
|
"scripts": {
|
|
35
38
|
"prepack": "yarn build",
|
|
36
39
|
"typecheck": "tsc --noEmit",
|
|
40
|
+
"test": "vp test run",
|
|
37
41
|
"build": "vp pack"
|
|
38
42
|
},
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"swc-plugin-coverage-instrument": "0.0.33"
|
|
45
|
+
},
|
|
39
46
|
"devDependencies": {
|
|
40
|
-
"rollipop": "1.0.0-alpha.
|
|
41
|
-
"typescript": "
|
|
42
|
-
"vite-plus": "0.
|
|
47
|
+
"rollipop": "1.0.0-alpha.30",
|
|
48
|
+
"typescript": "7.0.2",
|
|
49
|
+
"vite-plus": "0.3.3"
|
|
43
50
|
},
|
|
44
51
|
"peerDependencies": {
|
|
45
52
|
"@react-native/jest-preset": "*",
|
|
46
53
|
"react": "*",
|
|
47
54
|
"react-native": "*",
|
|
48
|
-
"rollipop": "1.0.0-alpha.
|
|
55
|
+
"rollipop": "1.0.0-alpha.30"
|
|
49
56
|
},
|
|
50
57
|
"peerDependenciesMeta": {
|
|
51
58
|
"@react-native/jest-preset": {
|
|
@@ -57,5 +64,8 @@
|
|
|
57
64
|
"react-native": {
|
|
58
65
|
"optional": true
|
|
59
66
|
}
|
|
67
|
+
},
|
|
68
|
+
"installConfig": {
|
|
69
|
+
"hoistingLimits": "none"
|
|
60
70
|
}
|
|
61
71
|
}
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
//#region \0rolldown/runtime.js
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __copyProps = (to, from, except, desc) => {
|
|
9
|
-
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
-
key = keys[i];
|
|
11
|
-
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
-
get: ((k) => from[k]).bind(null, key),
|
|
13
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
19
|
-
value: mod,
|
|
20
|
-
enumerable: true
|
|
21
|
-
}) : target, mod));
|
|
22
|
-
//#endregion
|
|
23
|
-
let node_crypto = require("node:crypto");
|
|
24
|
-
let node_path = require("node:path");
|
|
25
|
-
node_path = __toESM(node_path);
|
|
26
|
-
let rollipop = require("rollipop");
|
|
27
|
-
//#region src/env.ts
|
|
28
|
-
function defineEnvFromObject(env) {
|
|
29
|
-
return Object.fromEntries(Object.entries(env).map(([key, value]) => [`import.meta.env.${key}`, asLiteral(value)]));
|
|
30
|
-
}
|
|
31
|
-
function asLiteral(value) {
|
|
32
|
-
return JSON.stringify(value);
|
|
33
|
-
}
|
|
34
|
-
//#endregion
|
|
35
|
-
//#region src/transformer.ts
|
|
36
|
-
function resolveMode(mode = process.env.NODE_ENV) {
|
|
37
|
-
switch (mode) {
|
|
38
|
-
case "development":
|
|
39
|
-
case "production": return mode;
|
|
40
|
-
default: return "development";
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
function packageVersion() {
|
|
44
|
-
try {
|
|
45
|
-
return require(node_path.default.join(__dirname, "..", "package.json")).version;
|
|
46
|
-
} catch {
|
|
47
|
-
return "unknown";
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
function createTransformer(options = {}) {
|
|
51
|
-
const mode = resolveMode(options.mode);
|
|
52
|
-
const env = (0, rollipop.loadEnv)({
|
|
53
|
-
envDir: options.root ?? process.cwd(),
|
|
54
|
-
envFile: options.envFile ?? rollipop.Constants.DEFAULT_ENV_FILE,
|
|
55
|
-
envPrefix: options.envPrefix ?? rollipop.Constants.DEFAULT_ENV_PREFIX,
|
|
56
|
-
mode
|
|
57
|
-
});
|
|
58
|
-
const pipeline = new rollipop.rolldownExperimental.RollipopReactNativeTransformer({
|
|
59
|
-
envName: mode,
|
|
60
|
-
runtimeTarget: options.runtimeTarget,
|
|
61
|
-
swc: {
|
|
62
|
-
globals: {
|
|
63
|
-
"import.meta.hot": "undefined",
|
|
64
|
-
"import.meta.env": JSON.stringify({}),
|
|
65
|
-
...defineEnvFromObject(env),
|
|
66
|
-
...defineEnvFromObject({ MODE: mode })
|
|
67
|
-
},
|
|
68
|
-
react: {
|
|
69
|
-
development: mode === "development",
|
|
70
|
-
runtime: "Automatic"
|
|
71
|
-
},
|
|
72
|
-
module: { type: "commonjs" }
|
|
73
|
-
},
|
|
74
|
-
flow: options.flow,
|
|
75
|
-
worklets: options.worklets
|
|
76
|
-
});
|
|
77
|
-
const optionsHash = (0, node_crypto.createHash)("sha1").update(JSON.stringify({
|
|
78
|
-
version: packageVersion(),
|
|
79
|
-
options
|
|
80
|
-
})).digest("hex").slice(0, 16);
|
|
81
|
-
return {
|
|
82
|
-
canInstrument: false,
|
|
83
|
-
process(sourceText, sourcePath) {
|
|
84
|
-
const result = pipeline.transformSync(sourcePath, sourceText);
|
|
85
|
-
return {
|
|
86
|
-
code: result.code,
|
|
87
|
-
...result.map != null ? { map: result.map } : null
|
|
88
|
-
};
|
|
89
|
-
},
|
|
90
|
-
async processAsync(sourceText, sourcePath) {
|
|
91
|
-
const result = await pipeline.transform(sourcePath, sourceText);
|
|
92
|
-
return {
|
|
93
|
-
code: result.code,
|
|
94
|
-
...result.map != null ? { map: result.map } : null
|
|
95
|
-
};
|
|
96
|
-
},
|
|
97
|
-
getCacheKey(sourceText, sourcePath) {
|
|
98
|
-
return (0, node_crypto.createHash)("sha1").update(optionsHash).update("\0").update(sourcePath).update("\0").update(sourceText).digest("hex");
|
|
99
|
-
}
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
//#endregion
|
|
103
|
-
Object.defineProperty(exports, "createTransformer", {
|
|
104
|
-
enumerable: true,
|
|
105
|
-
get: function() {
|
|
106
|
-
return createTransformer;
|
|
107
|
-
}
|
|
108
|
-
});
|