one 1.16.12 → 1.17.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/dist/cjs/babel-preset/index.cjs +154 -0
- package/dist/cjs/babel-preset/index.native.js +186 -0
- package/dist/cjs/babel-preset/index.native.js.map +1 -0
- package/dist/cjs/babel-preset/index.test.cjs +143 -0
- package/dist/cjs/babel-preset/index.test.native.js +165 -0
- package/dist/cjs/babel-preset/index.test.native.js.map +1 -0
- package/dist/cjs/babel-preset/integration.test.cjs +94 -0
- package/dist/cjs/babel-preset/integration.test.native.js +97 -0
- package/dist/cjs/babel-preset/integration.test.native.js.map +1 -0
- package/dist/cjs/cli/generateBundlerConfig.cjs +247 -0
- package/dist/cjs/cli/generateBundlerConfig.native.js +316 -0
- package/dist/cjs/cli/generateBundlerConfig.native.js.map +1 -0
- package/dist/cjs/cli/generateBundlerConfig.test.cjs +350 -0
- package/dist/cjs/cli/generateBundlerConfig.test.native.js +380 -0
- package/dist/cjs/cli/generateBundlerConfig.test.native.js.map +1 -0
- package/dist/cjs/cli/patch.cjs +19 -2
- package/dist/cjs/cli/patch.native.js +26 -2
- package/dist/cjs/cli/patch.native.js.map +1 -1
- package/dist/cjs/cli/patch.test.cjs +56 -0
- package/dist/cjs/cli/patch.test.native.js +65 -0
- package/dist/cjs/cli/patch.test.native.js.map +1 -0
- package/dist/cjs/cli.cjs +39 -2
- package/dist/cjs/cli.native.js +40 -2
- package/dist/cjs/cli.native.js.map +1 -1
- package/dist/cjs/metro-config/buildOneMetroResolverOverrides.cjs +102 -0
- package/dist/cjs/metro-config/buildOneMetroResolverOverrides.native.js +109 -0
- package/dist/cjs/metro-config/buildOneMetroResolverOverrides.native.js.map +1 -0
- package/dist/cjs/metro-config/getViteMetroPluginOptions.cjs +17 -150
- package/dist/cjs/metro-config/getViteMetroPluginOptions.integration.test.cjs +84 -0
- package/dist/cjs/metro-config/getViteMetroPluginOptions.integration.test.native.js +90 -0
- package/dist/cjs/metro-config/getViteMetroPluginOptions.integration.test.native.js.map +1 -0
- package/dist/cjs/metro-config/getViteMetroPluginOptions.native.js +17 -158
- package/dist/cjs/metro-config/getViteMetroPluginOptions.native.js.map +1 -1
- package/dist/cjs/metro-config/withOne.cjs +82 -0
- package/dist/cjs/metro-config/withOne.native.js +88 -0
- package/dist/cjs/metro-config/withOne.native.js.map +1 -0
- package/dist/cjs/metro-config/withOne.test.cjs +129 -0
- package/dist/cjs/metro-config/withOne.test.native.js +156 -0
- package/dist/cjs/metro-config/withOne.test.native.js.map +1 -0
- package/dist/cjs/vite/loadConfig.cjs +20 -1
- package/dist/cjs/vite/loadConfig.native.js +20 -1
- package/dist/cjs/vite/loadConfig.native.js.map +1 -1
- package/dist/cjs/vite/plugins/warmRoutesPlugin.cjs +13 -7
- package/dist/cjs/vite/plugins/warmRoutesPlugin.native.js +13 -7
- package/dist/cjs/vite/plugins/warmRoutesPlugin.native.js.map +1 -1
- package/dist/esm/babel-preset/index.mjs +116 -0
- package/dist/esm/babel-preset/index.mjs.map +1 -0
- package/dist/esm/babel-preset/index.native.js +145 -0
- package/dist/esm/babel-preset/index.native.js.map +1 -0
- package/dist/esm/babel-preset/index.test.mjs +120 -0
- package/dist/esm/babel-preset/index.test.mjs.map +1 -0
- package/dist/esm/babel-preset/index.test.native.js +139 -0
- package/dist/esm/babel-preset/index.test.native.js.map +1 -0
- package/dist/esm/babel-preset/integration.test.mjs +71 -0
- package/dist/esm/babel-preset/integration.test.mjs.map +1 -0
- package/dist/esm/babel-preset/integration.test.native.js +71 -0
- package/dist/esm/babel-preset/integration.test.native.js.map +1 -0
- package/dist/esm/cli/generateBundlerConfig.mjs +207 -0
- package/dist/esm/cli/generateBundlerConfig.mjs.map +1 -0
- package/dist/esm/cli/generateBundlerConfig.native.js +273 -0
- package/dist/esm/cli/generateBundlerConfig.native.js.map +1 -0
- package/dist/esm/cli/generateBundlerConfig.test.mjs +327 -0
- package/dist/esm/cli/generateBundlerConfig.test.mjs.map +1 -0
- package/dist/esm/cli/generateBundlerConfig.test.native.js +354 -0
- package/dist/esm/cli/generateBundlerConfig.test.native.js.map +1 -0
- package/dist/esm/cli/patch.mjs +19 -2
- package/dist/esm/cli/patch.mjs.map +1 -1
- package/dist/esm/cli/patch.native.js +26 -2
- package/dist/esm/cli/patch.native.js.map +1 -1
- package/dist/esm/cli/patch.test.mjs +57 -0
- package/dist/esm/cli/patch.test.mjs.map +1 -0
- package/dist/esm/cli/patch.test.native.js +63 -0
- package/dist/esm/cli/patch.test.native.js.map +1 -0
- package/dist/esm/cli.mjs +39 -2
- package/dist/esm/cli.mjs.map +1 -1
- package/dist/esm/cli.native.js +40 -2
- package/dist/esm/cli.native.js.map +1 -1
- package/dist/esm/metro-config/buildOneMetroResolverOverrides.mjs +66 -0
- package/dist/esm/metro-config/buildOneMetroResolverOverrides.mjs.map +1 -0
- package/dist/esm/metro-config/buildOneMetroResolverOverrides.native.js +70 -0
- package/dist/esm/metro-config/buildOneMetroResolverOverrides.native.js.map +1 -0
- package/dist/esm/metro-config/getViteMetroPluginOptions.integration.test.mjs +61 -0
- package/dist/esm/metro-config/getViteMetroPluginOptions.integration.test.mjs.map +1 -0
- package/dist/esm/metro-config/getViteMetroPluginOptions.integration.test.native.js +64 -0
- package/dist/esm/metro-config/getViteMetroPluginOptions.integration.test.native.js.map +1 -0
- package/dist/esm/metro-config/getViteMetroPluginOptions.mjs +17 -138
- package/dist/esm/metro-config/getViteMetroPluginOptions.mjs.map +1 -1
- package/dist/esm/metro-config/getViteMetroPluginOptions.native.js +17 -146
- package/dist/esm/metro-config/getViteMetroPluginOptions.native.js.map +1 -1
- package/dist/esm/metro-config/withOne.mjs +45 -0
- package/dist/esm/metro-config/withOne.mjs.map +1 -0
- package/dist/esm/metro-config/withOne.native.js +48 -0
- package/dist/esm/metro-config/withOne.native.js.map +1 -0
- package/dist/esm/metro-config/withOne.test.mjs +106 -0
- package/dist/esm/metro-config/withOne.test.mjs.map +1 -0
- package/dist/esm/metro-config/withOne.test.native.js +130 -0
- package/dist/esm/metro-config/withOne.test.native.js.map +1 -0
- package/dist/esm/vite/loadConfig.mjs +20 -1
- package/dist/esm/vite/loadConfig.mjs.map +1 -1
- package/dist/esm/vite/loadConfig.native.js +20 -1
- package/dist/esm/vite/loadConfig.native.js.map +1 -1
- package/dist/esm/vite/plugins/warmRoutesPlugin.mjs +13 -7
- package/dist/esm/vite/plugins/warmRoutesPlugin.mjs.map +1 -1
- package/dist/esm/vite/plugins/warmRoutesPlugin.native.js +13 -7
- package/dist/esm/vite/plugins/warmRoutesPlugin.native.js.map +1 -1
- package/package.json +20 -9
- package/src/babel-preset/index.test.ts +148 -0
- package/src/babel-preset/index.ts +250 -0
- package/src/babel-preset/integration.test.ts +91 -0
- package/src/cli/generateBundlerConfig.test.ts +343 -0
- package/src/cli/generateBundlerConfig.ts +339 -0
- package/src/cli/patch.test.ts +65 -0
- package/src/cli/patch.ts +30 -2
- package/src/cli.ts +31 -0
- package/src/metro-config/buildOneMetroResolverOverrides.ts +104 -0
- package/src/metro-config/getViteMetroPluginOptions.integration.test.ts +75 -0
- package/src/metro-config/getViteMetroPluginOptions.ts +15 -230
- package/src/metro-config/withOne.test.ts +120 -0
- package/src/metro-config/withOne.ts +112 -0
- package/src/vite/loadConfig.ts +22 -0
- package/src/vite/plugins/warmRoutesPlugin.ts +22 -6
- package/types/babel-preset/index.d.ts +68 -0
- package/types/babel-preset/index.d.ts.map +1 -0
- package/types/babel-preset/index.test.d.ts +2 -0
- package/types/babel-preset/index.test.d.ts.map +1 -0
- package/types/babel-preset/integration.test.d.ts +2 -0
- package/types/babel-preset/integration.test.d.ts.map +1 -0
- package/types/cli/generateBundlerConfig.d.ts +61 -0
- package/types/cli/generateBundlerConfig.d.ts.map +1 -0
- package/types/cli/generateBundlerConfig.test.d.ts +2 -0
- package/types/cli/generateBundlerConfig.test.d.ts.map +1 -0
- package/types/cli/patch.d.ts.map +1 -1
- package/types/cli/patch.test.d.ts +2 -0
- package/types/cli/patch.test.d.ts.map +1 -0
- package/types/metro-config/buildOneMetroResolverOverrides.d.ts +20 -0
- package/types/metro-config/buildOneMetroResolverOverrides.d.ts.map +1 -0
- package/types/metro-config/getViteMetroPluginOptions.d.ts +0 -5
- package/types/metro-config/getViteMetroPluginOptions.d.ts.map +1 -1
- package/types/metro-config/getViteMetroPluginOptions.integration.test.d.ts +2 -0
- package/types/metro-config/getViteMetroPluginOptions.integration.test.d.ts.map +1 -0
- package/types/metro-config/withOne.d.ts +44 -0
- package/types/metro-config/withOne.d.ts.map +1 -0
- package/types/metro-config/withOne.test.d.ts +2 -0
- package/types/metro-config/withOne.test.d.ts.map +1 -0
- package/types/vite/loadConfig.d.ts +1 -0
- package/types/vite/loadConfig.d.ts.map +1 -1
- package/types/vite/plugins/warmRoutesPlugin.d.ts.map +1 -1
- package/dist/cjs/metro-config/getViteMetroPluginOptions.test.cjs +0 -23
- package/dist/cjs/metro-config/getViteMetroPluginOptions.test.native.js +0 -26
- package/dist/cjs/metro-config/getViteMetroPluginOptions.test.native.js.map +0 -1
- package/dist/esm/metro-config/getViteMetroPluginOptions.test.mjs +0 -24
- package/dist/esm/metro-config/getViteMetroPluginOptions.test.mjs.map +0 -1
- package/dist/esm/metro-config/getViteMetroPluginOptions.test.native.js +0 -24
- package/dist/esm/metro-config/getViteMetroPluginOptions.test.native.js.map +0 -1
- package/src/metro-config/getViteMetroPluginOptions.test.ts +0 -34
- package/types/metro-config/getViteMetroPluginOptions.test.d.ts +0 -2
- package/types/metro-config/getViteMetroPluginOptions.test.d.ts.map +0 -1
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all) __defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: true
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
16
|
+
get: () => from[key],
|
|
17
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
23
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
24
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
25
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
26
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
27
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
28
|
+
value: mod,
|
|
29
|
+
enumerable: true
|
|
30
|
+
}) : target, mod));
|
|
31
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
32
|
+
value: true
|
|
33
|
+
}), mod);
|
|
34
|
+
var babel_preset_exports = {};
|
|
35
|
+
__export(babel_preset_exports, {
|
|
36
|
+
buildOneBabelPlugins: () => buildOneBabelPlugins,
|
|
37
|
+
buildRouterRequireContextRegexString: () => buildRouterRequireContextRegexString,
|
|
38
|
+
default: () => oneBabelPreset
|
|
39
|
+
});
|
|
40
|
+
module.exports = __toCommonJS(babel_preset_exports);
|
|
41
|
+
var import_node_module = __toESM(require("node:module"), 1);
|
|
42
|
+
var import_node_path = __toESM(require("node:path"), 1);
|
|
43
|
+
var import_micromatch = __toESM(require("micromatch"), 1);
|
|
44
|
+
var import_tsconfig_paths = __toESM(require("tsconfig-paths"), 1);
|
|
45
|
+
var import_glob_patterns = require("../router/glob-patterns.cjs");
|
|
46
|
+
function oneBabelPreset(api, options = {}) {
|
|
47
|
+
const hasViteInjectedOnePlugins = typeof api?.caller === "function" ? api.caller(caller => !!caller?.oneViteMetroBabelConfig) : false;
|
|
48
|
+
if (!api?.caller && typeof api?.cache === "function") {
|
|
49
|
+
api.cache(true);
|
|
50
|
+
}
|
|
51
|
+
const projectRoot = import_node_path.default.resolve(options.projectRoot ?? (typeof api?.cwd === "function" ? api.cwd() : process.cwd()));
|
|
52
|
+
const presets = [];
|
|
53
|
+
if (options.includeExpoPreset !== false) {
|
|
54
|
+
const require2 = import_node_module.default.createRequire(projectRoot + "/");
|
|
55
|
+
try {
|
|
56
|
+
const expoPresetPath = require2.resolve("babel-preset-expo");
|
|
57
|
+
presets.push(require2(expoPresetPath));
|
|
58
|
+
} catch (e) {
|
|
59
|
+
throw new Error(`[one/babel-preset] Could not resolve 'babel-preset-expo' from ${projectRoot}. Install it as a project dependency (it ships with the Expo SDK). If you don't want the Expo base preset, pass { includeExpoPreset: false }.`);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return {
|
|
63
|
+
presets,
|
|
64
|
+
plugins: hasViteInjectedOnePlugins ? [] : buildOneBabelPlugins({
|
|
65
|
+
projectRoot,
|
|
66
|
+
relativeRouterRoot: options.routerRoot ?? "app",
|
|
67
|
+
ignoredRouteFiles: options.ignoredRouteFiles,
|
|
68
|
+
linking: options.linking,
|
|
69
|
+
setupFile: options.setupFile,
|
|
70
|
+
includeImportMetaEnv: options.includeImportMetaEnv
|
|
71
|
+
})
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
function buildOneBabelPlugins({
|
|
75
|
+
projectRoot,
|
|
76
|
+
relativeRouterRoot,
|
|
77
|
+
ignoredRouteFiles,
|
|
78
|
+
linking,
|
|
79
|
+
setupFile,
|
|
80
|
+
includeImportMetaEnv = true
|
|
81
|
+
}) {
|
|
82
|
+
const tsconfig = import_tsconfig_paths.default.loadConfig(projectRoot);
|
|
83
|
+
if (tsconfig.resultType === "failed") {
|
|
84
|
+
throw new Error("[one/babel-preset] tsconfig.json paths could not be loaded");
|
|
85
|
+
}
|
|
86
|
+
const require2 = import_node_module.default.createRequire(projectRoot + "/");
|
|
87
|
+
const metroEntryPath = require2.resolve("one/metro-entry", {
|
|
88
|
+
paths: [projectRoot]
|
|
89
|
+
});
|
|
90
|
+
const setupFileRelativeToMetroEntry = (() => {
|
|
91
|
+
if (!setupFile) return void 0;
|
|
92
|
+
const file = typeof setupFile === "string" ? setupFile : setupFile.native || setupFile.ios || setupFile.android;
|
|
93
|
+
if (!file) return void 0;
|
|
94
|
+
return import_node_path.default.relative(import_node_path.default.dirname(metroEntryPath), import_node_path.default.join(projectRoot, file));
|
|
95
|
+
})();
|
|
96
|
+
return [
|
|
97
|
+
// standalone Metro CLI (expo export, eas update) needs `import.meta.env.*` /
|
|
98
|
+
// `process.env.*` baked in. The Vite path passes `false` here and injects
|
|
99
|
+
// its own version with the user's `define` env via the server hook.
|
|
100
|
+
...(includeImportMetaEnv ? [["@vxrn/vite-plugin-metro/babel-plugins/import-meta-env-plugin", {
|
|
101
|
+
env: buildStandaloneImportMetaEnv()
|
|
102
|
+
}]] : []), "one/babel-plugin-environment-guard", ["one/babel-plugin-remove-server-code", {
|
|
103
|
+
routerRoot: relativeRouterRoot
|
|
104
|
+
}], ["babel-plugin-module-resolver",
|
|
105
|
+
// "vite-tsconfig-paths" for Metro
|
|
106
|
+
{
|
|
107
|
+
alias: Object.fromEntries(Object.entries(tsconfig.paths).map(([k, v]) => {
|
|
108
|
+
const key = k.endsWith("/*") ? k.replace(/\/\*$/, "") : `${k}$`;
|
|
109
|
+
let value = v[0].replace(/\/\*$/, "");
|
|
110
|
+
if (!value.startsWith("./")) value = `./${value}`;
|
|
111
|
+
return [key, value];
|
|
112
|
+
}))
|
|
113
|
+
}], ["one/babel-plugin-one-router-metro", {
|
|
114
|
+
ONE_ROUTER_APP_ROOT_RELATIVE_TO_ENTRY: import_node_path.default.relative(import_node_path.default.dirname(metroEntryPath), import_node_path.default.join(projectRoot, relativeRouterRoot)),
|
|
115
|
+
ONE_ROUTER_ROOT_FOLDER_NAME: relativeRouterRoot,
|
|
116
|
+
ONE_ROUTER_REQUIRE_CONTEXT_REGEX_STRING: buildRouterRequireContextRegexString(ignoredRouteFiles),
|
|
117
|
+
ONE_ROUTER_LINKING_CONFIG: linking,
|
|
118
|
+
ONE_SETUP_FILE_NATIVE: setupFileRelativeToMetroEntry
|
|
119
|
+
}], "one/babel-plugin-inline-one-server-url"];
|
|
120
|
+
}
|
|
121
|
+
function buildStandaloneImportMetaEnv() {
|
|
122
|
+
const isProduction = process.env.NODE_ENV !== "development";
|
|
123
|
+
const env = {
|
|
124
|
+
MODE: isProduction ? "production" : "development",
|
|
125
|
+
BASE_URL: "/",
|
|
126
|
+
PROD: isProduction,
|
|
127
|
+
DEV: !isProduction,
|
|
128
|
+
SSR: false
|
|
129
|
+
};
|
|
130
|
+
for (const [key, value] of Object.entries(process.env)) {
|
|
131
|
+
if (key.startsWith("EXPO_PUBLIC_") || key.startsWith("ONE_") || key.startsWith("VITE_")) {
|
|
132
|
+
env[key] = value;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return env;
|
|
136
|
+
}
|
|
137
|
+
function normalizeReSource(source) {
|
|
138
|
+
return source.replace(/\[\\\\\/\]/g, "\\/").replace(/\[\^\\\\\/\]/g, "[^/]");
|
|
139
|
+
}
|
|
140
|
+
function buildRouterRequireContextRegexString(ignoredRouteFiles) {
|
|
141
|
+
const excludeRes = [...(ignoredRouteFiles || []).map(pattern => import_micromatch.default.makeRe(pattern)), ...import_glob_patterns.ROUTE_NATIVE_EXCLUSION_GLOB_PATTERNS.map(pattern => import_micromatch.default.makeRe(pattern)), import_micromatch.default.makeRe(import_glob_patterns.API_ROUTE_GLOB_PATTERN)];
|
|
142
|
+
const mustStartWith = String.raw`^(?:(?:^|\/|(?:(?:(?!(?:^|\/)\.).)*?)\/)(?!\.)(?=.)[^/]*?`;
|
|
143
|
+
const mustEndWith = String.raw`)$`;
|
|
144
|
+
const negatives = excludeRes.map((re, i) => {
|
|
145
|
+
const reSource = normalizeReSource(re.source);
|
|
146
|
+
if (!(reSource.startsWith(mustStartWith) && reSource.endsWith(mustEndWith))) {
|
|
147
|
+
const pattern = ignoredRouteFiles?.[i];
|
|
148
|
+
throw new Error(pattern ? `[one/metro] ignoredRouteFile pattern "${pattern}" is not supported. We cannot process the corresponding regex "${reSource}" for now.` : `Unsupported regex "${reSource}" in "ignoredRouteFiles".`);
|
|
149
|
+
}
|
|
150
|
+
const inner = reSource.slice(mustStartWith.length, reSource.length - mustEndWith.length);
|
|
151
|
+
return String.raw`(?:.*${inner})`;
|
|
152
|
+
});
|
|
153
|
+
return String.raw`^(?:\.\/)(?!${negatives.join("|")}$).*\.tsx?$`;
|
|
154
|
+
}
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all) __defProp(target, name, {
|
|
11
|
+
get: all[name],
|
|
12
|
+
enumerable: true
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
var __copyProps = (to, from, except, desc) => {
|
|
16
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
17
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
18
|
+
get: () => from[key],
|
|
19
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
return to;
|
|
23
|
+
};
|
|
24
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
25
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
26
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
27
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
28
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
29
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
30
|
+
value: mod,
|
|
31
|
+
enumerable: true
|
|
32
|
+
}) : target, mod));
|
|
33
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
34
|
+
value: true
|
|
35
|
+
}), mod);
|
|
36
|
+
var babel_preset_exports = {};
|
|
37
|
+
__export(babel_preset_exports, {
|
|
38
|
+
buildOneBabelPlugins: () => buildOneBabelPlugins,
|
|
39
|
+
buildRouterRequireContextRegexString: () => buildRouterRequireContextRegexString,
|
|
40
|
+
default: () => oneBabelPreset
|
|
41
|
+
});
|
|
42
|
+
module.exports = __toCommonJS(babel_preset_exports);
|
|
43
|
+
var import_module = __toESM(require("module"), 1);
|
|
44
|
+
var import_path = __toESM(require("path"), 1);
|
|
45
|
+
var import_micromatch = __toESM(require("micromatch"), 1);
|
|
46
|
+
var import_tsconfig_paths = __toESM(require("tsconfig-paths"), 1);
|
|
47
|
+
var import_glob_patterns = require("../router/glob-patterns.native.js");
|
|
48
|
+
function oneBabelPreset(api) {
|
|
49
|
+
var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
50
|
+
var _options_projectRoot, _options_routerRoot;
|
|
51
|
+
var hasViteInjectedOnePlugins = typeof (api === null || api === void 0 ? void 0 : api.caller) === "function" ? api.caller(function (caller) {
|
|
52
|
+
return !!(caller === null || caller === void 0 ? void 0 : caller.oneViteMetroBabelConfig);
|
|
53
|
+
}) : false;
|
|
54
|
+
if (!(api === null || api === void 0 ? void 0 : api.caller) && typeof (api === null || api === void 0 ? void 0 : api.cache) === "function") {
|
|
55
|
+
api.cache(true);
|
|
56
|
+
}
|
|
57
|
+
var projectRoot = import_path.default.resolve((_options_projectRoot = options.projectRoot) !== null && _options_projectRoot !== void 0 ? _options_projectRoot : typeof (api === null || api === void 0 ? void 0 : api.cwd) === "function" ? api.cwd() : process.cwd());
|
|
58
|
+
var presets = [];
|
|
59
|
+
if (options.includeExpoPreset !== false) {
|
|
60
|
+
var require2 = import_module.default.createRequire(projectRoot + "/");
|
|
61
|
+
try {
|
|
62
|
+
var expoPresetPath = require2.resolve("babel-preset-expo");
|
|
63
|
+
presets.push(require2(expoPresetPath));
|
|
64
|
+
} catch (e) {
|
|
65
|
+
throw new Error(`[one/babel-preset] Could not resolve 'babel-preset-expo' from ${projectRoot}. Install it as a project dependency (it ships with the Expo SDK). If you don't want the Expo base preset, pass { includeExpoPreset: false }.`);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return {
|
|
69
|
+
presets,
|
|
70
|
+
plugins: hasViteInjectedOnePlugins ? [] : buildOneBabelPlugins({
|
|
71
|
+
projectRoot,
|
|
72
|
+
relativeRouterRoot: (_options_routerRoot = options.routerRoot) !== null && _options_routerRoot !== void 0 ? _options_routerRoot : "app",
|
|
73
|
+
ignoredRouteFiles: options.ignoredRouteFiles,
|
|
74
|
+
linking: options.linking,
|
|
75
|
+
setupFile: options.setupFile,
|
|
76
|
+
includeImportMetaEnv: options.includeImportMetaEnv
|
|
77
|
+
})
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
function buildOneBabelPlugins(param) {
|
|
81
|
+
var {
|
|
82
|
+
projectRoot,
|
|
83
|
+
relativeRouterRoot,
|
|
84
|
+
ignoredRouteFiles,
|
|
85
|
+
linking,
|
|
86
|
+
setupFile,
|
|
87
|
+
includeImportMetaEnv = true
|
|
88
|
+
} = param;
|
|
89
|
+
var tsconfig = import_tsconfig_paths.default.loadConfig(projectRoot);
|
|
90
|
+
if (tsconfig.resultType === "failed") {
|
|
91
|
+
throw new Error("[one/babel-preset] tsconfig.json paths could not be loaded");
|
|
92
|
+
}
|
|
93
|
+
var require2 = import_module.default.createRequire(projectRoot + "/");
|
|
94
|
+
var metroEntryPath = require2.resolve("one/metro-entry", {
|
|
95
|
+
paths: [projectRoot]
|
|
96
|
+
});
|
|
97
|
+
var setupFileRelativeToMetroEntry = function () {
|
|
98
|
+
if (!setupFile) return void 0;
|
|
99
|
+
var file = typeof setupFile === "string" ? setupFile : setupFile.native || setupFile.ios || setupFile.android;
|
|
100
|
+
if (!file) return void 0;
|
|
101
|
+
return import_path.default.relative(import_path.default.dirname(metroEntryPath), import_path.default.join(projectRoot, file));
|
|
102
|
+
}();
|
|
103
|
+
return [
|
|
104
|
+
// standalone Metro CLI (expo export, eas update) needs `import.meta.env.*` /
|
|
105
|
+
// `process.env.*` baked in. The Vite path passes `false` here and injects
|
|
106
|
+
// its own version with the user's `define` env via the server hook.
|
|
107
|
+
...(includeImportMetaEnv ? [["@vxrn/vite-plugin-metro/babel-plugins/import-meta-env-plugin", {
|
|
108
|
+
env: buildStandaloneImportMetaEnv()
|
|
109
|
+
}]] : []), "one/babel-plugin-environment-guard", ["one/babel-plugin-remove-server-code", {
|
|
110
|
+
routerRoot: relativeRouterRoot
|
|
111
|
+
}], ["babel-plugin-module-resolver",
|
|
112
|
+
// "vite-tsconfig-paths" for Metro
|
|
113
|
+
{
|
|
114
|
+
alias: Object.fromEntries(Object.entries(tsconfig.paths).map(function (param2) {
|
|
115
|
+
var [k, v] = param2;
|
|
116
|
+
var key = k.endsWith("/*") ? k.replace(/\/\*$/, "") : `${k}$`;
|
|
117
|
+
var value = v[0].replace(/\/\*$/, "");
|
|
118
|
+
if (!value.startsWith("./")) value = `./${value}`;
|
|
119
|
+
return [key, value];
|
|
120
|
+
}))
|
|
121
|
+
}], ["one/babel-plugin-one-router-metro", {
|
|
122
|
+
ONE_ROUTER_APP_ROOT_RELATIVE_TO_ENTRY: import_path.default.relative(import_path.default.dirname(metroEntryPath), import_path.default.join(projectRoot, relativeRouterRoot)),
|
|
123
|
+
ONE_ROUTER_ROOT_FOLDER_NAME: relativeRouterRoot,
|
|
124
|
+
ONE_ROUTER_REQUIRE_CONTEXT_REGEX_STRING: buildRouterRequireContextRegexString(ignoredRouteFiles),
|
|
125
|
+
ONE_ROUTER_LINKING_CONFIG: linking,
|
|
126
|
+
ONE_SETUP_FILE_NATIVE: setupFileRelativeToMetroEntry
|
|
127
|
+
}], "one/babel-plugin-inline-one-server-url"];
|
|
128
|
+
}
|
|
129
|
+
function buildStandaloneImportMetaEnv() {
|
|
130
|
+
var isProduction = process.env.NODE_ENV !== "development";
|
|
131
|
+
var env = {
|
|
132
|
+
MODE: isProduction ? "production" : "development",
|
|
133
|
+
BASE_URL: "/",
|
|
134
|
+
PROD: isProduction,
|
|
135
|
+
DEV: !isProduction,
|
|
136
|
+
SSR: false
|
|
137
|
+
};
|
|
138
|
+
var _iteratorNormalCompletion = true,
|
|
139
|
+
_didIteratorError = false,
|
|
140
|
+
_iteratorError = void 0;
|
|
141
|
+
try {
|
|
142
|
+
for (var _iterator = Object.entries(process.env)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
143
|
+
var [key, value] = _step.value;
|
|
144
|
+
if (key.startsWith("EXPO_PUBLIC_") || key.startsWith("ONE_") || key.startsWith("VITE_")) {
|
|
145
|
+
env[key] = value;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
} catch (err) {
|
|
149
|
+
_didIteratorError = true;
|
|
150
|
+
_iteratorError = err;
|
|
151
|
+
} finally {
|
|
152
|
+
try {
|
|
153
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
154
|
+
_iterator.return();
|
|
155
|
+
}
|
|
156
|
+
} finally {
|
|
157
|
+
if (_didIteratorError) {
|
|
158
|
+
throw _iteratorError;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return env;
|
|
163
|
+
}
|
|
164
|
+
function normalizeReSource(source) {
|
|
165
|
+
return source.replace(/\[\\\\\/\]/g, "\\/").replace(/\[\^\\\\\/\]/g, "[^/]");
|
|
166
|
+
}
|
|
167
|
+
function buildRouterRequireContextRegexString(ignoredRouteFiles) {
|
|
168
|
+
var excludeRes = [...(ignoredRouteFiles || []).map(function (pattern) {
|
|
169
|
+
return import_micromatch.default.makeRe(pattern);
|
|
170
|
+
}), ...import_glob_patterns.ROUTE_NATIVE_EXCLUSION_GLOB_PATTERNS.map(function (pattern) {
|
|
171
|
+
return import_micromatch.default.makeRe(pattern);
|
|
172
|
+
}), import_micromatch.default.makeRe(import_glob_patterns.API_ROUTE_GLOB_PATTERN)];
|
|
173
|
+
var mustStartWith = String.raw`^(?:(?:^|\/|(?:(?:(?!(?:^|\/)\.).)*?)\/)(?!\.)(?=.)[^/]*?`;
|
|
174
|
+
var mustEndWith = String.raw`)$`;
|
|
175
|
+
var negatives = excludeRes.map(function (re, i) {
|
|
176
|
+
var reSource = normalizeReSource(re.source);
|
|
177
|
+
if (!(reSource.startsWith(mustStartWith) && reSource.endsWith(mustEndWith))) {
|
|
178
|
+
var pattern = ignoredRouteFiles === null || ignoredRouteFiles === void 0 ? void 0 : ignoredRouteFiles[i];
|
|
179
|
+
throw new Error(pattern ? `[one/metro] ignoredRouteFile pattern "${pattern}" is not supported. We cannot process the corresponding regex "${reSource}" for now.` : `Unsupported regex "${reSource}" in "ignoredRouteFiles".`);
|
|
180
|
+
}
|
|
181
|
+
var inner = reSource.slice(mustStartWith.length, reSource.length - mustEndWith.length);
|
|
182
|
+
return String.raw`(?:.*${inner})`;
|
|
183
|
+
});
|
|
184
|
+
return String.raw`^(?:\.\/)(?!${negatives.join("|")}$).*\.tsx?$`;
|
|
185
|
+
}
|
|
186
|
+
//# sourceMappingURL=index.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","babel_preset_exports","__export","buildOneBabelPlugins","buildRouterRequireContextRegexString","default","oneBabelPreset","module","exports","import_module","__toESM","require","import_path","import_micromatch","import_tsconfig_paths","import_glob_patterns","api","options","arguments","length","_options_projectRoot","_options_routerRoot","hasViteInjectedOnePlugins","caller","oneViteMetroBabelConfig","cache","projectRoot","resolve","cwd","process","presets","includeExpoPreset","require2","createRequire","expoPresetPath","push","e","Error","plugins","relativeRouterRoot","routerRoot","ignoredRouteFiles","linking","setupFile","includeImportMetaEnv","param","tsconfig","loadConfig","resultType","metroEntryPath","paths","setupFileRelativeToMetroEntry","file","native","ios","android","relative","dirname","join","env","buildStandaloneImportMetaEnv","alias","Object","fromEntries","entries","map","param2","k","v","key","endsWith","replace","startsWith","ONE_ROUTER_APP_ROOT_RELATIVE_TO_ENTRY","ONE_ROUTER_ROOT_FOLDER_NAME","ONE_ROUTER_REQUIRE_CONTEXT_REGEX_STRING","ONE_ROUTER_LINKING_CONFIG","ONE_SETUP_FILE_NATIVE","isProduction","NODE_ENV","MODE","BASE_URL","PROD","DEV","SSR","_iteratorNormalCompletion","_didIteratorError","_iteratorError","_iterator","Symbol","iterator","_step","next","done","err","return","normalizeReSource","source"],"sources":["../../../src/babel-preset/index.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;EAAAC,KAAA;AAAA,IAAAH,GAAA;AAAA,IAAAI,oBAAA;AAAAC,QAAA,CAAAD,oBAAA;EAAAE,oBAAA,EAAAA,CAAA,KAAAA,oBAAA;EAAAC,oCAAA,EAAAA,CAAA,KAAAA,oCAAA;EAAAC,OAAA,EAAAA,CAAA,KAAAC;AAAA;AAAAC,MAAA,CAAAC,OAAA,GAAAZ,YAAmB,CAAAK,oBAAA;AACnB,IAAAQ,aAAA,GAAAC,OA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ACA,IAAAC,yBAAO;IAAAC,iBAAA;IAAAC,cAAA;EACT;IAMA,KAAS,IAAAC,SAAA,GAAA1B,MAAkB,CAAAE,OAAwB,CAAAnC,OAAA,CAAA8B,GAAA,EAAA8B,MAAA,CAAAC,QAAA,KAAAC,KAAA,IAAAN,yBAAA,IAAAM,KAAA,GAAAH,SAAA,CAAAI,IAAA,IAAAC,IAAA,GAAAR,yBAAA;MACjD,IAAO,CAAAhB,GAAA,EAAOrE,KAAA,IAAQ2F,KAAA,CAAA3F,KAAA;MACxB,IAAAqE,GAAA,CAAAG,UAAA,oBAAAH,GAAA,CAAAG,UAAA,YAAAH,GAAA,CAAAG,UAAA;QAEOb,GAAS,CAAAU,GAAA,IAAArE,KAAA;MAGd;IACE;EAAgE,EAChE,OAAG8F,GAAA;IACHR,iBAAA;IACFC,cAAA,GAAAO,GAAA;EAEA,UAAM;IAEN,IAAM;MAEN,IAAM,CAAAT,yBAA4B,IAAIG,SAAM,CAAAO,MAAA;QAC1CP,SAAM,CAAAO,MAAW;MACjB;IACE,UAAM;MACN,IAAAT,iBAAU;QACR,MAAAC,cACI;MAEN;IACF;EACA;EAEA,OAAA5B,GAAO;AAAuB;AAGhC,SAAOqC,iBAAOA,CAAAC,MAAA,EAAkB;EAClC,OAAAA,MAAA,CAAA1B,OAAA,uBAAAA,OAAA","ignoreList":[]}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __copyProps = (to, from, except, desc) => {
|
|
8
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
9
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
10
|
+
get: () => from[key],
|
|
11
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
return to;
|
|
15
|
+
};
|
|
16
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
17
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
18
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
19
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
20
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
22
|
+
value: mod,
|
|
23
|
+
enumerable: true
|
|
24
|
+
}) : target, mod));
|
|
25
|
+
var import_node_path = __toESM(require("node:path"), 1);
|
|
26
|
+
var import_vitest = require("vitest");
|
|
27
|
+
var import_index = __toESM(require("./index.cjs"), 1);
|
|
28
|
+
const projectRoot = import_node_path.default.resolve(__dirname, "../../");
|
|
29
|
+
const fakeApi = cwd => ({
|
|
30
|
+
cache: () => {},
|
|
31
|
+
cwd: () => cwd
|
|
32
|
+
});
|
|
33
|
+
(0, import_vitest.describe)("one/babel-preset", () => {
|
|
34
|
+
(0, import_vitest.it)("returns presets and plugins", () => {
|
|
35
|
+
const result = (0, import_index.default)(fakeApi(projectRoot), {
|
|
36
|
+
projectRoot,
|
|
37
|
+
// skip the babel-preset-expo lookup so this test runs without the
|
|
38
|
+
// expo SDK installed in the workspace root
|
|
39
|
+
includeExpoPreset: false
|
|
40
|
+
});
|
|
41
|
+
(0, import_vitest.expect)(result).toHaveProperty("plugins");
|
|
42
|
+
(0, import_vitest.expect)(Array.isArray(result.plugins)).toBe(true);
|
|
43
|
+
(0, import_vitest.expect)(result.plugins).toHaveLength(6);
|
|
44
|
+
});
|
|
45
|
+
(0, import_vitest.it)("orders the plugin chain so server code is removed before router transforms", () => {
|
|
46
|
+
const {
|
|
47
|
+
plugins
|
|
48
|
+
} = (0, import_index.default)(fakeApi(projectRoot), {
|
|
49
|
+
projectRoot,
|
|
50
|
+
includeExpoPreset: false
|
|
51
|
+
});
|
|
52
|
+
const names = (plugins ?? []).map(p => Array.isArray(p) ? p[0] : p);
|
|
53
|
+
(0, import_vitest.expect)(names).toEqual(["@vxrn/vite-plugin-metro/babel-plugins/import-meta-env-plugin", "one/babel-plugin-environment-guard", "one/babel-plugin-remove-server-code", "babel-plugin-module-resolver", "one/babel-plugin-one-router-metro", "one/babel-plugin-inline-one-server-url"]);
|
|
54
|
+
});
|
|
55
|
+
(0, import_vitest.it)('defaults routerRoot to "app"', () => {
|
|
56
|
+
const {
|
|
57
|
+
plugins
|
|
58
|
+
} = (0, import_index.default)(fakeApi(projectRoot), {
|
|
59
|
+
projectRoot,
|
|
60
|
+
includeExpoPreset: false
|
|
61
|
+
});
|
|
62
|
+
const removeServer = (plugins ?? []).find(p => Array.isArray(p) && p[0] === "one/babel-plugin-remove-server-code");
|
|
63
|
+
(0, import_vitest.expect)(removeServer?.[1].routerRoot).toBe("app");
|
|
64
|
+
});
|
|
65
|
+
(0, import_vitest.it)("threads custom routerRoot through", () => {
|
|
66
|
+
const {
|
|
67
|
+
plugins
|
|
68
|
+
} = (0, import_index.default)(fakeApi(projectRoot), {
|
|
69
|
+
projectRoot,
|
|
70
|
+
routerRoot: "src/routes",
|
|
71
|
+
includeExpoPreset: false
|
|
72
|
+
});
|
|
73
|
+
const removeServer = (plugins ?? []).find(p => Array.isArray(p) && p[0] === "one/babel-plugin-remove-server-code");
|
|
74
|
+
(0, import_vitest.expect)(removeServer?.[1].routerRoot).toBe("src/routes");
|
|
75
|
+
});
|
|
76
|
+
(0, import_vitest.it)("skips the One plugin chain when the Vite Metro caller already injected it", () => {
|
|
77
|
+
const result = (0, import_index.default)({
|
|
78
|
+
cache: () => {},
|
|
79
|
+
cwd: () => projectRoot,
|
|
80
|
+
caller: cb => cb({
|
|
81
|
+
oneViteMetroBabelConfig: true
|
|
82
|
+
})
|
|
83
|
+
}, {
|
|
84
|
+
projectRoot,
|
|
85
|
+
includeExpoPreset: false
|
|
86
|
+
});
|
|
87
|
+
(0, import_vitest.expect)(result.plugins).toEqual([]);
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
(0, import_vitest.describe)("buildOneBabelPlugins", () => {
|
|
91
|
+
(0, import_vitest.it)("produces the canonical One plugin chain (no env plugin)", () => {
|
|
92
|
+
const plugins = (0, import_index.buildOneBabelPlugins)({
|
|
93
|
+
projectRoot,
|
|
94
|
+
relativeRouterRoot: "app",
|
|
95
|
+
ignoredRouteFiles: [],
|
|
96
|
+
linking: void 0,
|
|
97
|
+
setupFile: void 0,
|
|
98
|
+
// skip the import-meta-env plugin so the assertion covers the One-only chain
|
|
99
|
+
includeImportMetaEnv: false
|
|
100
|
+
});
|
|
101
|
+
(0, import_vitest.expect)(plugins).toHaveLength(5);
|
|
102
|
+
(0, import_vitest.expect)(plugins[0]).toBe("one/babel-plugin-environment-guard");
|
|
103
|
+
(0, import_vitest.expect)(plugins[1]).toEqual(["one/babel-plugin-remove-server-code", {
|
|
104
|
+
routerRoot: "app"
|
|
105
|
+
}]);
|
|
106
|
+
(0, import_vitest.expect)(plugins[2]).toMatchObject(["babel-plugin-module-resolver", {
|
|
107
|
+
alias: {}
|
|
108
|
+
}]);
|
|
109
|
+
const oneRouterMetro = plugins[3];
|
|
110
|
+
(0, import_vitest.expect)(oneRouterMetro[0]).toBe("one/babel-plugin-one-router-metro");
|
|
111
|
+
(0, import_vitest.expect)(oneRouterMetro[1]).toMatchObject({
|
|
112
|
+
ONE_ROUTER_ROOT_FOLDER_NAME: "app",
|
|
113
|
+
ONE_ROUTER_LINKING_CONFIG: void 0,
|
|
114
|
+
ONE_SETUP_FILE_NATIVE: void 0
|
|
115
|
+
});
|
|
116
|
+
(0, import_vitest.expect)(typeof oneRouterMetro[1].ONE_ROUTER_APP_ROOT_RELATIVE_TO_ENTRY).toBe("string");
|
|
117
|
+
(0, import_vitest.expect)(typeof oneRouterMetro[1].ONE_ROUTER_REQUIRE_CONTEXT_REGEX_STRING).toBe("string");
|
|
118
|
+
(0, import_vitest.expect)(plugins[4]).toBe("one/babel-plugin-inline-one-server-url");
|
|
119
|
+
});
|
|
120
|
+
(0, import_vitest.it)("threads setupFile through as a path relative to the metro entry", () => {
|
|
121
|
+
const plugins = (0, import_index.buildOneBabelPlugins)({
|
|
122
|
+
projectRoot,
|
|
123
|
+
relativeRouterRoot: "app",
|
|
124
|
+
setupFile: "src/setup-native.ts",
|
|
125
|
+
includeImportMetaEnv: false
|
|
126
|
+
});
|
|
127
|
+
const oneRouterMetro = plugins[3];
|
|
128
|
+
(0, import_vitest.expect)(oneRouterMetro[1].ONE_SETUP_FILE_NATIVE).toMatch(/setup-native\.ts$/);
|
|
129
|
+
});
|
|
130
|
+
(0, import_vitest.it)("passes the linking config through", () => {
|
|
131
|
+
const linking = {
|
|
132
|
+
prefixes: ["myapp://"]
|
|
133
|
+
};
|
|
134
|
+
const plugins = (0, import_index.buildOneBabelPlugins)({
|
|
135
|
+
projectRoot,
|
|
136
|
+
relativeRouterRoot: "app",
|
|
137
|
+
linking,
|
|
138
|
+
includeImportMetaEnv: false
|
|
139
|
+
});
|
|
140
|
+
const oneRouterMetro = plugins[3];
|
|
141
|
+
(0, import_vitest.expect)(oneRouterMetro[1].ONE_ROUTER_LINKING_CONFIG).toBe(linking);
|
|
142
|
+
});
|
|
143
|
+
});
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
+
get: () => from[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(
|
|
19
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
20
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
21
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
22
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
23
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
24
|
+
value: mod,
|
|
25
|
+
enumerable: true
|
|
26
|
+
}) : target, mod));
|
|
27
|
+
var import_path = __toESM(require("path"), 1);
|
|
28
|
+
var import_vitest = require("vitest");
|
|
29
|
+
var import_index = __toESM(require("./index.native.js"), 1);
|
|
30
|
+
function _type_of(obj) {
|
|
31
|
+
"@swc/helpers - typeof";
|
|
32
|
+
|
|
33
|
+
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
34
|
+
}
|
|
35
|
+
var projectRoot = import_path.default.resolve(__dirname, "../../");
|
|
36
|
+
var fakeApi = function (cwd) {
|
|
37
|
+
return {
|
|
38
|
+
cache: function () {},
|
|
39
|
+
cwd: function () {
|
|
40
|
+
return cwd;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
(0, import_vitest.describe)("one/babel-preset", function () {
|
|
45
|
+
(0, import_vitest.it)("returns presets and plugins", function () {
|
|
46
|
+
var result = (0, import_index.default)(fakeApi(projectRoot), {
|
|
47
|
+
projectRoot,
|
|
48
|
+
// skip the babel-preset-expo lookup so this test runs without the
|
|
49
|
+
// expo SDK installed in the workspace root
|
|
50
|
+
includeExpoPreset: false
|
|
51
|
+
});
|
|
52
|
+
(0, import_vitest.expect)(result).toHaveProperty("plugins");
|
|
53
|
+
(0, import_vitest.expect)(Array.isArray(result.plugins)).toBe(true);
|
|
54
|
+
(0, import_vitest.expect)(result.plugins).toHaveLength(6);
|
|
55
|
+
});
|
|
56
|
+
(0, import_vitest.it)("orders the plugin chain so server code is removed before router transforms", function () {
|
|
57
|
+
var {
|
|
58
|
+
plugins
|
|
59
|
+
} = (0, import_index.default)(fakeApi(projectRoot), {
|
|
60
|
+
projectRoot,
|
|
61
|
+
includeExpoPreset: false
|
|
62
|
+
});
|
|
63
|
+
var names = (plugins !== null && plugins !== void 0 ? plugins : []).map(function (p) {
|
|
64
|
+
return Array.isArray(p) ? p[0] : p;
|
|
65
|
+
});
|
|
66
|
+
(0, import_vitest.expect)(names).toEqual(["@vxrn/vite-plugin-metro/babel-plugins/import-meta-env-plugin", "one/babel-plugin-environment-guard", "one/babel-plugin-remove-server-code", "babel-plugin-module-resolver", "one/babel-plugin-one-router-metro", "one/babel-plugin-inline-one-server-url"]);
|
|
67
|
+
});
|
|
68
|
+
(0, import_vitest.it)('defaults routerRoot to "app"', function () {
|
|
69
|
+
var {
|
|
70
|
+
plugins
|
|
71
|
+
} = (0, import_index.default)(fakeApi(projectRoot), {
|
|
72
|
+
projectRoot,
|
|
73
|
+
includeExpoPreset: false
|
|
74
|
+
});
|
|
75
|
+
var removeServer = (plugins !== null && plugins !== void 0 ? plugins : []).find(function (p) {
|
|
76
|
+
return Array.isArray(p) && p[0] === "one/babel-plugin-remove-server-code";
|
|
77
|
+
});
|
|
78
|
+
(0, import_vitest.expect)(removeServer === null || removeServer === void 0 ? void 0 : removeServer[1].routerRoot).toBe("app");
|
|
79
|
+
});
|
|
80
|
+
(0, import_vitest.it)("threads custom routerRoot through", function () {
|
|
81
|
+
var {
|
|
82
|
+
plugins
|
|
83
|
+
} = (0, import_index.default)(fakeApi(projectRoot), {
|
|
84
|
+
projectRoot,
|
|
85
|
+
routerRoot: "src/routes",
|
|
86
|
+
includeExpoPreset: false
|
|
87
|
+
});
|
|
88
|
+
var removeServer = (plugins !== null && plugins !== void 0 ? plugins : []).find(function (p) {
|
|
89
|
+
return Array.isArray(p) && p[0] === "one/babel-plugin-remove-server-code";
|
|
90
|
+
});
|
|
91
|
+
(0, import_vitest.expect)(removeServer === null || removeServer === void 0 ? void 0 : removeServer[1].routerRoot).toBe("src/routes");
|
|
92
|
+
});
|
|
93
|
+
(0, import_vitest.it)("skips the One plugin chain when the Vite Metro caller already injected it", function () {
|
|
94
|
+
var result = (0, import_index.default)({
|
|
95
|
+
cache: function () {},
|
|
96
|
+
cwd: function () {
|
|
97
|
+
return projectRoot;
|
|
98
|
+
},
|
|
99
|
+
caller: function (cb) {
|
|
100
|
+
return cb({
|
|
101
|
+
oneViteMetroBabelConfig: true
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
}, {
|
|
105
|
+
projectRoot,
|
|
106
|
+
includeExpoPreset: false
|
|
107
|
+
});
|
|
108
|
+
(0, import_vitest.expect)(result.plugins).toEqual([]);
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
(0, import_vitest.describe)("buildOneBabelPlugins", function () {
|
|
112
|
+
(0, import_vitest.it)("produces the canonical One plugin chain (no env plugin)", function () {
|
|
113
|
+
var plugins = (0, import_index.buildOneBabelPlugins)({
|
|
114
|
+
projectRoot,
|
|
115
|
+
relativeRouterRoot: "app",
|
|
116
|
+
ignoredRouteFiles: [],
|
|
117
|
+
linking: void 0,
|
|
118
|
+
setupFile: void 0,
|
|
119
|
+
// skip the import-meta-env plugin so the assertion covers the One-only chain
|
|
120
|
+
includeImportMetaEnv: false
|
|
121
|
+
});
|
|
122
|
+
(0, import_vitest.expect)(plugins).toHaveLength(5);
|
|
123
|
+
(0, import_vitest.expect)(plugins[0]).toBe("one/babel-plugin-environment-guard");
|
|
124
|
+
(0, import_vitest.expect)(plugins[1]).toEqual(["one/babel-plugin-remove-server-code", {
|
|
125
|
+
routerRoot: "app"
|
|
126
|
+
}]);
|
|
127
|
+
(0, import_vitest.expect)(plugins[2]).toMatchObject(["babel-plugin-module-resolver", {
|
|
128
|
+
alias: {}
|
|
129
|
+
}]);
|
|
130
|
+
var oneRouterMetro = plugins[3];
|
|
131
|
+
(0, import_vitest.expect)(oneRouterMetro[0]).toBe("one/babel-plugin-one-router-metro");
|
|
132
|
+
(0, import_vitest.expect)(oneRouterMetro[1]).toMatchObject({
|
|
133
|
+
ONE_ROUTER_ROOT_FOLDER_NAME: "app",
|
|
134
|
+
ONE_ROUTER_LINKING_CONFIG: void 0,
|
|
135
|
+
ONE_SETUP_FILE_NATIVE: void 0
|
|
136
|
+
});
|
|
137
|
+
(0, import_vitest.expect)(_type_of(oneRouterMetro[1].ONE_ROUTER_APP_ROOT_RELATIVE_TO_ENTRY)).toBe("string");
|
|
138
|
+
(0, import_vitest.expect)(_type_of(oneRouterMetro[1].ONE_ROUTER_REQUIRE_CONTEXT_REGEX_STRING)).toBe("string");
|
|
139
|
+
(0, import_vitest.expect)(plugins[4]).toBe("one/babel-plugin-inline-one-server-url");
|
|
140
|
+
});
|
|
141
|
+
(0, import_vitest.it)("threads setupFile through as a path relative to the metro entry", function () {
|
|
142
|
+
var plugins = (0, import_index.buildOneBabelPlugins)({
|
|
143
|
+
projectRoot,
|
|
144
|
+
relativeRouterRoot: "app",
|
|
145
|
+
setupFile: "src/setup-native.ts",
|
|
146
|
+
includeImportMetaEnv: false
|
|
147
|
+
});
|
|
148
|
+
var oneRouterMetro = plugins[3];
|
|
149
|
+
(0, import_vitest.expect)(oneRouterMetro[1].ONE_SETUP_FILE_NATIVE).toMatch(/setup-native\.ts$/);
|
|
150
|
+
});
|
|
151
|
+
(0, import_vitest.it)("passes the linking config through", function () {
|
|
152
|
+
var linking = {
|
|
153
|
+
prefixes: ["myapp://"]
|
|
154
|
+
};
|
|
155
|
+
var plugins = (0, import_index.buildOneBabelPlugins)({
|
|
156
|
+
projectRoot,
|
|
157
|
+
relativeRouterRoot: "app",
|
|
158
|
+
linking,
|
|
159
|
+
includeImportMetaEnv: false
|
|
160
|
+
});
|
|
161
|
+
var oneRouterMetro = plugins[3];
|
|
162
|
+
(0, import_vitest.expect)(oneRouterMetro[1].ONE_ROUTER_LINKING_CONFIG).toBe(linking);
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
//# sourceMappingURL=index.test.native.js.map
|