@rollipop/jest-preset 1.0.0-alpha.29 → 1.0.0-alpha.31

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 CHANGED
@@ -1,2 +1,2 @@
1
- import { TransformerOptions, createTransformer } from "./transformer.js";
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-aU6_6W3G.js");
2
+ const require_transformer = require("./transformer-B9RYZvsj.js");
3
3
  exports.createTransformer = require_transformer.createTransformer;
package/dist/mock.d.ts CHANGED
@@ -1,16 +1,15 @@
1
1
  //#region src/mock.d.ts
2
- type GlobImportPattern = string | string[];
3
- type GlobImportOptions = Record<string, unknown>;
4
- type GlobImportResult = Record<string, unknown>;
5
- interface GlobImportContext {
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
6
  importer: string;
7
7
  pattern: GlobImportPattern;
8
8
  options?: GlobImportOptions;
9
9
  }
10
- type GlobImportMock = (context: GlobImportContext) => GlobImportResult;
11
- declare function createGlobImport(importer: string): (pattern: GlobImportPattern, options?: GlobImportOptions) => GlobImportResult;
12
- declare function mockGlobImport(implementation: GlobImportMock): void;
13
- declare function resetGlobImport(): void;
14
- declare function resetRollipopJestPresetMocks(): void;
15
- //#endregion
16
- export { GlobImportContext, GlobImportMock, GlobImportOptions, GlobImportPattern, GlobImportResult, createGlobImport, mockGlobImport, resetGlobImport, resetRollipopJestPresetMocks };
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
@@ -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 };
@@ -1,25 +1,2 @@
1
- import { rolldownExperimental } from "rollipop";
2
- //#region src/transformer.d.ts
3
- interface TransformerOptions {
4
- mode?: 'development' | 'production';
5
- root?: string;
6
- runtimeTarget?: rolldownExperimental.RollipopReactNativeRuntimeTarget;
7
- flow?: rolldownExperimental.RollipopReactNativeFlowConfig;
8
- worklets?: rolldownExperimental.RollipopReactNativeWorkletsConfig;
9
- envDir?: string;
10
- envFile?: string;
11
- envPrefix?: string;
12
- }
13
- interface JestTransformOutput {
14
- code: string;
15
- map?: string;
16
- }
17
- interface JestSyncTransformer {
18
- canInstrument: false;
19
- process(sourceText: string, sourcePath: string): JestTransformOutput;
20
- processAsync(sourceText: string, sourcePath: string): Promise<JestTransformOutput>;
21
- getCacheKey(sourceText: string, sourcePath: string): string;
22
- }
23
- declare function createTransformer(options?: TransformerOptions): JestSyncTransformer;
24
- //#endregion
25
- 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 };
@@ -1,3 +1,3 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_transformer = require("./transformer-aU6_6W3G.js");
2
+ const require_transformer = require("./transformer-B9RYZvsj.js");
3
3
  exports.createTransformer = require_transformer.createTransformer;
package/package.json CHANGED
@@ -1,7 +1,6 @@
1
1
  {
2
2
  "name": "@rollipop/jest-preset",
3
- "version": "1.0.0-alpha.29",
4
- "stableVersion": "1.0.0-alpha.23",
3
+ "version": "1.0.0-alpha.31",
5
4
  "homepage": "https://github.com/rollipop-dev/rollipop#readme",
6
5
  "bugs": {
7
6
  "url": "https://github.com/rollipop-dev/rollipop/issues"
@@ -38,18 +37,22 @@
38
37
  "scripts": {
39
38
  "prepack": "yarn build",
40
39
  "typecheck": "tsc --noEmit",
40
+ "test": "vp test run",
41
41
  "build": "vp pack"
42
42
  },
43
+ "dependencies": {
44
+ "swc-plugin-coverage-instrument": "0.0.33"
45
+ },
43
46
  "devDependencies": {
44
- "rollipop": "1.0.0-alpha.29",
45
- "typescript": "6.0.3",
46
- "vite-plus": "0.2.5"
47
+ "rollipop": "1.0.0-alpha.31",
48
+ "typescript": "7.0.2",
49
+ "vite-plus": "0.3.3"
47
50
  },
48
51
  "peerDependencies": {
49
52
  "@react-native/jest-preset": "*",
50
53
  "react": "*",
51
54
  "react-native": "*",
52
- "rollipop": "1.0.0-alpha.29"
55
+ "rollipop": "1.0.0-alpha.31"
53
56
  },
54
57
  "peerDependenciesMeta": {
55
58
  "@react-native/jest-preset": {
@@ -61,5 +64,8 @@
61
64
  "react-native": {
62
65
  "optional": true
63
66
  }
67
+ },
68
+ "installConfig": {
69
+ "hoistingLimits": "none"
64
70
  }
65
71
  }
@@ -1,110 +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
- const GLOB_IMPORT_HELPER = "require(\"@rollipop/jest-preset/mock\").createGlobImport(__filename)";
37
- function resolveMode(mode = process.env.NODE_ENV) {
38
- switch (mode) {
39
- case "development":
40
- case "production": return mode;
41
- default: return "development";
42
- }
43
- }
44
- function packageVersion() {
45
- try {
46
- return require(node_path.default.join(__dirname, "..", "package.json")).version;
47
- } catch {
48
- return "unknown";
49
- }
50
- }
51
- function createTransformer(options = {}) {
52
- const mode = resolveMode(options.mode);
53
- const env = (0, rollipop.loadEnv)({
54
- envDir: options.root ?? process.cwd(),
55
- envFile: options.envFile ?? rollipop.Constants.DEFAULT_ENV_FILE,
56
- envPrefix: options.envPrefix ?? rollipop.Constants.DEFAULT_ENV_PREFIX,
57
- mode
58
- });
59
- const pipeline = new rollipop.rolldownExperimental.RollipopReactNativeTransformer({
60
- envName: mode,
61
- runtimeTarget: options.runtimeTarget,
62
- swc: {
63
- globals: {
64
- "import.meta.hot": "undefined",
65
- "import.meta.env": JSON.stringify({}),
66
- "import.meta.glob": GLOB_IMPORT_HELPER,
67
- ...defineEnvFromObject(env),
68
- ...defineEnvFromObject({ MODE: mode })
69
- },
70
- react: {
71
- development: mode === "development",
72
- runtime: "Automatic"
73
- },
74
- module: { type: "commonjs" }
75
- },
76
- flow: options.flow,
77
- worklets: options.worklets
78
- });
79
- const optionsHash = (0, node_crypto.createHash)("sha1").update(JSON.stringify({
80
- version: packageVersion(),
81
- options
82
- })).digest("hex").slice(0, 16);
83
- return {
84
- canInstrument: false,
85
- process(sourceText, sourcePath) {
86
- const result = pipeline.transformSync(sourcePath, sourceText);
87
- return {
88
- code: result.code,
89
- ...result.map != null ? { map: result.map } : null
90
- };
91
- },
92
- async processAsync(sourceText, sourcePath) {
93
- const result = await pipeline.transform(sourcePath, sourceText);
94
- return {
95
- code: result.code,
96
- ...result.map != null ? { map: result.map } : null
97
- };
98
- },
99
- getCacheKey(sourceText, sourcePath) {
100
- return (0, node_crypto.createHash)("sha1").update(optionsHash).update("\0").update(sourcePath).update("\0").update(sourceText).digest("hex");
101
- }
102
- };
103
- }
104
- //#endregion
105
- Object.defineProperty(exports, "createTransformer", {
106
- enumerable: true,
107
- get: function() {
108
- return createTransformer;
109
- }
110
- });