rollipop 0.1.0-alpha.16 → 0.1.0-alpha.18
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/CHANGELOG.md +12 -0
- package/dist/commands.cjs +206 -148
- package/dist/commands.js +207 -149
- package/dist/hmr-runtime.iife.js +8 -8
- package/dist/index.d.ts +121 -27
- package/dist/index.js +210 -152
- package/dist/runtime.cjs +2 -2
- package/dist/runtime.js +2 -2
- package/package.json +6 -17
- package/src/runtime/hmr-client.ts +322 -0
- package/src/runtime/hmr-runtime.ts +271 -0
- package/src/runtime/react-native-core.d.ts +37 -0
- package/src/runtime/react-refresh-utils.ts +37 -0
- package/src/runtime/runtime-utils.ts +57 -0
- package/dist/plugins.cjs +0 -166
- package/dist/plugins.d.cts +0 -648
- package/dist/plugins.d.ts +0 -647
- package/dist/plugins.js +0 -143
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# rollipop
|
|
2
2
|
|
|
3
|
+
## 0.1.0-alpha.18
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- fa83644: trigger publish
|
|
8
|
+
|
|
9
|
+
## 0.1.0-alpha.17
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 5985887: Include `src/runtime/hmr-client.ts` in the published tarball. The `./hmr-client` export maps to this raw TypeScript source, but the `files` field in `package.json` only listed `bin`, `dist`, and `client.d.ts` — so consumers hitting `import 'rollipop/hmr-client'` against a published version would fail to resolve the file.
|
|
14
|
+
|
|
3
15
|
## 0.1.0-alpha.16
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/dist/commands.cjs
CHANGED
|
@@ -86,7 +86,6 @@ ajv = __toESM(ajv);
|
|
|
86
86
|
let _babel_code_frame = require("@babel/code-frame");
|
|
87
87
|
let ws = require("ws");
|
|
88
88
|
ws = __toESM(ws);
|
|
89
|
-
let _svgr_core = require("@svgr/core");
|
|
90
89
|
let _babel_core = require("@babel/core");
|
|
91
90
|
_babel_core = __toESM(_babel_core);
|
|
92
91
|
let _swc_core = require("@swc/core");
|
|
@@ -480,7 +479,7 @@ async function stripFlowTypes(id, code) {
|
|
|
480
479
|
//#endregion
|
|
481
480
|
//#region src/constants.ts
|
|
482
481
|
const ROLLIPOP_VERSION = globalThis.__ROLLIPOP_VERSION__;
|
|
483
|
-
const GLOBAL_IDENTIFIER = "
|
|
482
|
+
const GLOBAL_IDENTIFIER = "global";
|
|
484
483
|
/**
|
|
485
484
|
* @see {@link https://github.com/facebook/metro/blob/0.81.x/docs/Configuration.md#resolvermainfields}
|
|
486
485
|
*/
|
|
@@ -542,6 +541,7 @@ const DEFAULT_ASSET_EXTENSIONS = [
|
|
|
542
541
|
const DEFAULT_ASSET_REGISTRY_PATH = "react-native/Libraries/Image/AssetRegistry.js";
|
|
543
542
|
const DEFAULT_HMR_CLIENT_PATH = "react-native/Libraries/Utilities/HMRClient.js";
|
|
544
543
|
const DEFAULT_REACT_NATIVE_GLOBAL_IDENTIFIERS = [
|
|
544
|
+
GLOBAL_IDENTIFIER,
|
|
545
545
|
"Promise",
|
|
546
546
|
"regeneratorRuntime",
|
|
547
547
|
"XMLHttpRequest",
|
|
@@ -596,6 +596,7 @@ const DEFAULT_REACT_NATIVE_GLOBAL_IDENTIFIERS = [
|
|
|
596
596
|
"TaskAttributionTiming"
|
|
597
597
|
];
|
|
598
598
|
const DEFAULT_ENV_PREFIX = "ROLLIPOP_";
|
|
599
|
+
const DEFAULT_RUNTIME_TARGET = "hermes-v1";
|
|
599
600
|
//#endregion
|
|
600
601
|
//#region src/internal/react-native.ts
|
|
601
602
|
function getInitializeCorePath(basePath) {
|
|
@@ -634,6 +635,16 @@ function resolvePackagePath(basePath, packageName) {
|
|
|
634
635
|
} catch {}
|
|
635
636
|
throw new Error(`Failed to resolve package path for '${packageName}'`);
|
|
636
637
|
}
|
|
638
|
+
function resolvePackageJson(basePath, packageName) {
|
|
639
|
+
try {
|
|
640
|
+
const packagePath = resolvePackagePath(basePath, packageName);
|
|
641
|
+
const packageJsonPath = node_path.default.join(packagePath, "package.json");
|
|
642
|
+
const rawPackageJson = node_fs.default.readFileSync(packageJsonPath, "utf-8");
|
|
643
|
+
return JSON.parse(rawPackageJson);
|
|
644
|
+
} catch {
|
|
645
|
+
return null;
|
|
646
|
+
}
|
|
647
|
+
}
|
|
637
648
|
function resolvePackagePathWithNodeRequire(basePath, packageName, subpath) {
|
|
638
649
|
const resolvedPath = require.resolve(subpath ? `${packageName}/${subpath}` : packageName, { paths: [basePath] });
|
|
639
650
|
const root = node_path.default.parse(resolvedPath).root;
|
|
@@ -987,13 +998,10 @@ async function getDefaultConfig(projectRoot, mode) {
|
|
|
987
998
|
preferNativePlatform: true,
|
|
988
999
|
symlinks: true
|
|
989
1000
|
},
|
|
990
|
-
transformer: {
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
code: /@flow/
|
|
995
|
-
} }
|
|
996
|
-
},
|
|
1001
|
+
transformer: { flow: { filter: {
|
|
1002
|
+
id: /\.jsx?$/,
|
|
1003
|
+
code: /@flow/
|
|
1004
|
+
} } },
|
|
997
1005
|
serializer: {
|
|
998
1006
|
prelude: [getInitializeCorePath(projectRoot)],
|
|
999
1007
|
polyfills: await Promise.all(getPolyfillScriptPaths(reactNativePath).map(async (path) => {
|
|
@@ -1024,7 +1032,9 @@ async function getDefaultConfig(projectRoot, mode) {
|
|
|
1024
1032
|
return "compat";
|
|
1025
1033
|
})() },
|
|
1026
1034
|
envDir: projectRoot,
|
|
1027
|
-
envPrefix: DEFAULT_ENV_PREFIX
|
|
1035
|
+
envPrefix: DEFAULT_ENV_PREFIX,
|
|
1036
|
+
runtimeTarget: DEFAULT_RUNTIME_TARGET,
|
|
1037
|
+
experimental: { nativeTransformPipeline: false }
|
|
1028
1038
|
};
|
|
1029
1039
|
}
|
|
1030
1040
|
//#endregion
|
|
@@ -1087,11 +1097,14 @@ async function loadConfig(options = {}) {
|
|
|
1087
1097
|
...commonOptions
|
|
1088
1098
|
});
|
|
1089
1099
|
const plugins = await flattenPluginOption(userConfig.plugins);
|
|
1090
|
-
const
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1100
|
+
const resolvedConfig = {
|
|
1101
|
+
...await resolvePluginConfig(mergeConfig(defaultConfig, {
|
|
1102
|
+
...userConfig,
|
|
1103
|
+
plugins
|
|
1104
|
+
}), plugins),
|
|
1105
|
+
plugins,
|
|
1106
|
+
dangerously_overrideRolldownOptions: userConfig.dangerously_overrideRolldownOptions
|
|
1107
|
+
};
|
|
1095
1108
|
await invokeConfigResolved(resolvedConfig, plugins);
|
|
1096
1109
|
return resolvedConfig;
|
|
1097
1110
|
}
|
|
@@ -1226,9 +1239,6 @@ function indent(text, indent, space = " ") {
|
|
|
1226
1239
|
function asLiteral(value) {
|
|
1227
1240
|
return JSON.stringify(value);
|
|
1228
1241
|
}
|
|
1229
|
-
function asIdentifier(name) {
|
|
1230
|
-
return name;
|
|
1231
|
-
}
|
|
1232
1242
|
function nodeEnvironment(dev) {
|
|
1233
1243
|
return dev ? "development" : "production";
|
|
1234
1244
|
}
|
|
@@ -1292,6 +1302,14 @@ function defineEnvFromObject(env) {
|
|
|
1292
1302
|
return Object.fromEntries(Object.entries(env).map(([key, value]) => [`import.meta.env.${key}`, asLiteral(value)]));
|
|
1293
1303
|
}
|
|
1294
1304
|
//#endregion
|
|
1305
|
+
//#region src/utils/runtime-target.ts
|
|
1306
|
+
function resolveRuntimeTarget(target) {
|
|
1307
|
+
switch (target) {
|
|
1308
|
+
case "hermes": return "Hermes";
|
|
1309
|
+
default: return "HermesV1";
|
|
1310
|
+
}
|
|
1311
|
+
}
|
|
1312
|
+
//#endregion
|
|
1295
1313
|
//#region src/utils/server.ts
|
|
1296
1314
|
function getBaseUrl(host, port, https) {
|
|
1297
1315
|
return `${https ? "https" : "http"}://${host}:${port}`;
|
|
@@ -1460,7 +1478,7 @@ var FileSystemBundleStore = class {
|
|
|
1460
1478
|
code,
|
|
1461
1479
|
mtimeMs: stats.mtimeMs
|
|
1462
1480
|
};
|
|
1463
|
-
logger$1.
|
|
1481
|
+
logger$1.debug(`File system bundle created at ${bundleFilePath}`);
|
|
1464
1482
|
}
|
|
1465
1483
|
update() {
|
|
1466
1484
|
this.holder = {
|
|
@@ -2932,8 +2950,8 @@ function withTransformBoundary(context, plugins) {
|
|
|
2932
2950
|
}
|
|
2933
2951
|
//#endregion
|
|
2934
2952
|
//#region src/core/plugins/react-native-plugin.ts
|
|
2935
|
-
function reactNativePlugin(
|
|
2936
|
-
const {
|
|
2953
|
+
function reactNativePlugin(options) {
|
|
2954
|
+
const { projectRoot, platform, preferNativePlatform, buildType, assetsDir, assetExtensions, assetRegistryPath, flowFilter, codegenFilter, builtinPluginConfig } = options;
|
|
2937
2955
|
const codegenPlugin = {
|
|
2938
2956
|
name: "rollipop:react-native-codegen-marker",
|
|
2939
2957
|
transform: {
|
|
@@ -2970,10 +2988,10 @@ function reactNativePlugin(config, options) {
|
|
|
2970
2988
|
async handler(id) {
|
|
2971
2989
|
this.debug(`Asset ${id} found`);
|
|
2972
2990
|
const assetData = await resolveScaledAssets({
|
|
2973
|
-
projectRoot
|
|
2991
|
+
projectRoot,
|
|
2974
2992
|
assetPath: id,
|
|
2975
|
-
platform
|
|
2976
|
-
preferNativePlatform
|
|
2993
|
+
platform,
|
|
2994
|
+
preferNativePlatform
|
|
2977
2995
|
});
|
|
2978
2996
|
assets.push(assetData);
|
|
2979
2997
|
return {
|
|
@@ -2993,33 +3011,13 @@ function reactNativePlugin(config, options) {
|
|
|
2993
3011
|
await copyAssetsToDestination({
|
|
2994
3012
|
assets,
|
|
2995
3013
|
assetsDir,
|
|
2996
|
-
platform
|
|
2997
|
-
preferNativePlatform
|
|
3014
|
+
platform,
|
|
3015
|
+
preferNativePlatform
|
|
2998
3016
|
});
|
|
2999
3017
|
}
|
|
3000
3018
|
}
|
|
3001
3019
|
};
|
|
3002
|
-
|
|
3003
|
-
const hmrConfig = resolveHmrConfig(config);
|
|
3004
|
-
const replaceHMRClientPlugin = {
|
|
3005
|
-
name: "rollipop:react-native-replace-hmr-client",
|
|
3006
|
-
load: {
|
|
3007
|
-
filter: [(0, _rollipop_rolldown_pluginutils.include)((0, _rollipop_rolldown_pluginutils.id)((0, _rollipop_rolldown_pluginutils.exactRegex)(hmrClientPath)))],
|
|
3008
|
-
handler(id) {
|
|
3009
|
-
this.debug(`Replacing HMR client: ${id}`);
|
|
3010
|
-
return {
|
|
3011
|
-
code: hmrConfig?.clientImplement ?? defaultRuntimeImplements.clientImplement,
|
|
3012
|
-
moduleType: "ts"
|
|
3013
|
-
};
|
|
3014
|
-
}
|
|
3015
|
-
}
|
|
3016
|
-
};
|
|
3017
|
-
return [
|
|
3018
|
-
codegenPlugin,
|
|
3019
|
-
stripFlowSyntaxPlugin,
|
|
3020
|
-
assetPlugin,
|
|
3021
|
-
...(buildType === "serve" ? [replaceHMRClientPlugin] : null) ?? []
|
|
3022
|
-
];
|
|
3020
|
+
return [...builtinPluginConfig ? [(0, _rollipop_rolldown_experimental.rollipopReactNativePlugin)(builtinPluginConfig)] : [codegenPlugin, stripFlowSyntaxPlugin], assetPlugin];
|
|
3023
3021
|
}
|
|
3024
3022
|
//#endregion
|
|
3025
3023
|
//#region src/core/plugins/prelude-plugin.ts
|
|
@@ -3072,42 +3070,9 @@ function jsonPlugin() {
|
|
|
3072
3070
|
};
|
|
3073
3071
|
}
|
|
3074
3072
|
//#endregion
|
|
3075
|
-
//#region src/core/plugins/svg-plugin.ts
|
|
3076
|
-
function svgPlugin(options) {
|
|
3077
|
-
if (!options.enabled) return null;
|
|
3078
|
-
return {
|
|
3079
|
-
name: "rollipop:svg",
|
|
3080
|
-
load: {
|
|
3081
|
-
filter: { id: /\.svg$/ },
|
|
3082
|
-
async handler(id) {
|
|
3083
|
-
return {
|
|
3084
|
-
code: await (0, _svgr_core.transform)(node_fs.default.readFileSync(id, "utf-8"), {
|
|
3085
|
-
template: defaultTemplate,
|
|
3086
|
-
plugins: [require.resolve("@svgr/plugin-jsx")],
|
|
3087
|
-
native: true
|
|
3088
|
-
}, { filePath: id }),
|
|
3089
|
-
moduleType: "jsx"
|
|
3090
|
-
};
|
|
3091
|
-
}
|
|
3092
|
-
}
|
|
3093
|
-
};
|
|
3094
|
-
}
|
|
3095
|
-
const SVG_COMPONENT_NAME = "SvgLogo";
|
|
3096
|
-
const defaultTemplate = (variables, { tpl }) => {
|
|
3097
|
-
return tpl`${variables.imports};
|
|
3098
|
-
|
|
3099
|
-
${variables.interfaces};
|
|
3100
|
-
|
|
3101
|
-
const ${SVG_COMPONENT_NAME} = (${variables.props}) => (
|
|
3102
|
-
${variables.jsx}
|
|
3103
|
-
);
|
|
3104
|
-
|
|
3105
|
-
export default ${SVG_COMPONENT_NAME};`;
|
|
3106
|
-
};
|
|
3107
|
-
//#endregion
|
|
3108
3073
|
//#region src/utils/babel.ts
|
|
3109
|
-
function mergeBabelOptions(
|
|
3110
|
-
return options.reduce((acc, options) => (0, es_toolkit.mergeWith)(acc, options, merge$3),
|
|
3074
|
+
function mergeBabelOptions(options) {
|
|
3075
|
+
return options.reduce((acc, options) => (0, es_toolkit.mergeWith)(acc, options, merge$3), {});
|
|
3111
3076
|
}
|
|
3112
3077
|
function merge$3(target, source, key) {
|
|
3113
3078
|
if (key === "plugins") return [...target ?? [], ...source ?? []];
|
|
@@ -3124,8 +3089,8 @@ function isJSX(id) {
|
|
|
3124
3089
|
}
|
|
3125
3090
|
//#endregion
|
|
3126
3091
|
//#region src/core/plugins/babel-plugin.ts
|
|
3127
|
-
function babelPlugin(
|
|
3128
|
-
const { rules = [] } =
|
|
3092
|
+
function babelPlugin({ useNativeTransformPipeline, transformConfig }) {
|
|
3093
|
+
const { rules = [] } = transformConfig ?? {};
|
|
3129
3094
|
const babelOptionsById = /* @__PURE__ */ new Map();
|
|
3130
3095
|
const babelRules = rules.map(({ filter, options }, index) => {
|
|
3131
3096
|
return {
|
|
@@ -3149,14 +3114,14 @@ function babelPlugin(options) {
|
|
|
3149
3114
|
const flags = getFlag(this, id);
|
|
3150
3115
|
if (flags & TransformFlag.SKIP_ALL) return;
|
|
3151
3116
|
const babelOptions = babelOptionsById.get(id) ?? [];
|
|
3152
|
-
if (!(flags & TransformFlag.CODEGEN_REQUIRED || babelOptions.length > 0)) return;
|
|
3153
|
-
const baseOptions = getPreset
|
|
3117
|
+
if (!(useNativeTransformPipeline ? babelOptions.length > 0 : flags & TransformFlag.CODEGEN_REQUIRED || babelOptions.length > 0)) return;
|
|
3118
|
+
const baseOptions = useNativeTransformPipeline ? [] : [getPreset(flags, id)];
|
|
3154
3119
|
const result = _babel_core.transformSync(code, {
|
|
3155
3120
|
filename: id,
|
|
3156
3121
|
babelrc: false,
|
|
3157
3122
|
configFile: false,
|
|
3158
3123
|
sourceMaps: true,
|
|
3159
|
-
...mergeBabelOptions(baseOptions, ...babelOptions)
|
|
3124
|
+
...mergeBabelOptions([...baseOptions, ...babelOptions])
|
|
3160
3125
|
});
|
|
3161
3126
|
(0, es_toolkit.invariant)(result?.code, `Failed to transform with babel: ${id}`);
|
|
3162
3127
|
return {
|
|
@@ -3167,7 +3132,7 @@ function babelPlugin(options) {
|
|
|
3167
3132
|
};
|
|
3168
3133
|
return [...babelRules, babelPlugin];
|
|
3169
3134
|
}
|
|
3170
|
-
function getPreset
|
|
3135
|
+
function getPreset(flags, id) {
|
|
3171
3136
|
const presets = [];
|
|
3172
3137
|
const plugins = [];
|
|
3173
3138
|
let parserOpts = null;
|
|
@@ -3191,8 +3156,8 @@ function getPreset$1(flags, id) {
|
|
|
3191
3156
|
}
|
|
3192
3157
|
//#endregion
|
|
3193
3158
|
//#region src/utils/swc.ts
|
|
3194
|
-
function mergeSwcOptions(
|
|
3195
|
-
return options.reduce((acc, options) => (0, es_toolkit.mergeWith)(acc, options, merge$2),
|
|
3159
|
+
function mergeSwcOptions(options) {
|
|
3160
|
+
return options.reduce((acc, options) => (0, es_toolkit.mergeWith)(acc, options, merge$2), {});
|
|
3196
3161
|
}
|
|
3197
3162
|
function merge$2(target, source, key) {
|
|
3198
3163
|
if (key === "plugins") return [...target ?? [], ...source ?? []];
|
|
@@ -3202,8 +3167,8 @@ function merge$2(target, source, key) {
|
|
|
3202
3167
|
const ROLLDOWN_RUNTIME_EXCLUDE_FILTER = (0, _rollipop_rolldown_pluginutils.exclude)((0, _rollipop_rolldown_pluginutils.or)((0, _rollipop_rolldown_pluginutils.id)(/rolldown\/runtime/), (0, _rollipop_rolldown_pluginutils.id)(/@oxc-project\+runtime/)));
|
|
3203
3168
|
//#endregion
|
|
3204
3169
|
//#region src/core/plugins/swc-plugin.ts
|
|
3205
|
-
function swcPlugin(
|
|
3206
|
-
const { rules = [] } =
|
|
3170
|
+
function swcPlugin({ useNativeTransformPipeline, runtimeTarget, transformConfig }) {
|
|
3171
|
+
const { rules = [] } = transformConfig ?? {};
|
|
3207
3172
|
const swcOptionsById = /* @__PURE__ */ new Map();
|
|
3208
3173
|
const swcHelpersResolvePlugin = {
|
|
3209
3174
|
name: "rollipop:swc-helpers-resolve",
|
|
@@ -3228,6 +3193,7 @@ function swcPlugin(options) {
|
|
|
3228
3193
|
}
|
|
3229
3194
|
};
|
|
3230
3195
|
});
|
|
3196
|
+
const getSwcPreset = useNativeTransformPipeline ? null : presets[runtimeTarget];
|
|
3231
3197
|
const swcPlugin = {
|
|
3232
3198
|
name: "rollipop:swc",
|
|
3233
3199
|
buildStart() {
|
|
@@ -3238,14 +3204,15 @@ function swcPlugin(options) {
|
|
|
3238
3204
|
handler(code, id) {
|
|
3239
3205
|
if (getFlag(this, id) & TransformFlag.SKIP_ALL) return;
|
|
3240
3206
|
const swcOptions = swcOptionsById.get(id) ?? [];
|
|
3241
|
-
|
|
3207
|
+
if (getSwcPreset == null && swcOptions.length === 0) return;
|
|
3208
|
+
const baseOptions = getSwcPreset != null ? [getSwcPreset(id)] : [];
|
|
3242
3209
|
const result = _swc_core.transformSync(code, {
|
|
3243
3210
|
filename: id,
|
|
3244
3211
|
configFile: false,
|
|
3245
3212
|
swcrc: false,
|
|
3246
3213
|
sourceMaps: true,
|
|
3247
3214
|
inputSourceMap: false,
|
|
3248
|
-
...mergeSwcOptions(baseOptions, ...swcOptions)
|
|
3215
|
+
...mergeSwcOptions([...baseOptions, ...swcOptions])
|
|
3249
3216
|
});
|
|
3250
3217
|
return {
|
|
3251
3218
|
code: result.code,
|
|
@@ -3260,8 +3227,8 @@ function swcPlugin(options) {
|
|
|
3260
3227
|
swcPlugin
|
|
3261
3228
|
];
|
|
3262
3229
|
}
|
|
3263
|
-
|
|
3264
|
-
|
|
3230
|
+
const presets = {
|
|
3231
|
+
"hermes-v1": (id) => ({
|
|
3265
3232
|
env: {
|
|
3266
3233
|
targets: { node: 9999 },
|
|
3267
3234
|
include: [
|
|
@@ -3280,8 +3247,26 @@ function getPreset(id) {
|
|
|
3280
3247
|
externalHelpers: true
|
|
3281
3248
|
},
|
|
3282
3249
|
isModule: id.endsWith(".cjs") ? "commonjs" : true
|
|
3283
|
-
}
|
|
3284
|
-
|
|
3250
|
+
}),
|
|
3251
|
+
hermes: (id) => ({
|
|
3252
|
+
jsc: {
|
|
3253
|
+
parser: {
|
|
3254
|
+
syntax: "typescript",
|
|
3255
|
+
tsx: true
|
|
3256
|
+
},
|
|
3257
|
+
transform: { react: { runtime: "preserve" } },
|
|
3258
|
+
externalHelpers: true,
|
|
3259
|
+
keepClassNames: true,
|
|
3260
|
+
loose: false,
|
|
3261
|
+
assumptions: {
|
|
3262
|
+
setPublicClassFields: true,
|
|
3263
|
+
privateFieldsAsProperties: true
|
|
3264
|
+
},
|
|
3265
|
+
target: "es5"
|
|
3266
|
+
},
|
|
3267
|
+
isModule: id.endsWith(".cjs") ? "commonjs" : true
|
|
3268
|
+
})
|
|
3269
|
+
};
|
|
3285
3270
|
//#endregion
|
|
3286
3271
|
//#region src/core/plugins/reporter-plugin.ts
|
|
3287
3272
|
function reporterPlugin(options) {
|
|
@@ -3332,6 +3317,29 @@ function reporterPlugin(options) {
|
|
|
3332
3317
|
};
|
|
3333
3318
|
}
|
|
3334
3319
|
//#endregion
|
|
3320
|
+
//#region src/core/plugins/dev-server-plugin.ts
|
|
3321
|
+
async function devServerPlugin(options) {
|
|
3322
|
+
const { cwd, hmrClientPath, hmrConfig } = options;
|
|
3323
|
+
if (hmrConfig == null) return null;
|
|
3324
|
+
return [{
|
|
3325
|
+
name: "rollipop:replace-hmr-client",
|
|
3326
|
+
load: {
|
|
3327
|
+
filter: [(0, _rollipop_rolldown_pluginutils.include)((0, _rollipop_rolldown_pluginutils.id)((0, _rollipop_rolldown_pluginutils.exactRegex)(resolveFrom(cwd, typeof hmrClientPath === "function" ? await hmrClientPath(cwd) : hmrClientPath))))],
|
|
3328
|
+
handler(id) {
|
|
3329
|
+
this.debug(`Replacing HMR client: ${id}`);
|
|
3330
|
+
return {
|
|
3331
|
+
code: hmrConfig.clientImplement,
|
|
3332
|
+
moduleType: "ts"
|
|
3333
|
+
};
|
|
3334
|
+
}
|
|
3335
|
+
}
|
|
3336
|
+
}, (0, _rollipop_rolldown_experimental.rollipopReactRefreshWrapperPlugin)({
|
|
3337
|
+
cwd,
|
|
3338
|
+
include: [/\.[tj]sx?(?:$|\?)/],
|
|
3339
|
+
exclude: [/\/node_modules\//]
|
|
3340
|
+
})];
|
|
3341
|
+
}
|
|
3342
|
+
//#endregion
|
|
3335
3343
|
//#region src/core/rolldown.ts
|
|
3336
3344
|
resolveRolldownOptions.cache = /* @__PURE__ */ new Map();
|
|
3337
3345
|
async function resolveRolldownOptions(context, config, buildOptions, devEngineOptions) {
|
|
@@ -3345,18 +3353,18 @@ async function resolveRolldownOptions(context, config, buildOptions, devEngineOp
|
|
|
3345
3353
|
MODE: config.mode,
|
|
3346
3354
|
...isDevServerMode ? { BASE_URL: getBaseUrl(devEngineOptions.host, devEngineOptions.port, devEngineOptions.https) } : null
|
|
3347
3355
|
};
|
|
3356
|
+
const hmrConfig = resolveHmrConfig(config);
|
|
3357
|
+
const hmrEnabled = hmrConfig != null;
|
|
3348
3358
|
const { sourceExtensions, assetExtensions, preferNativePlatform, external: rolldownExternal, ...rolldownResolve } = config.resolver;
|
|
3349
|
-
const { polyfills,
|
|
3350
|
-
const { flow, babel:
|
|
3359
|
+
const { polyfills, banner: rolldownBanner, footer: rolldownFooter, postBanner: rolldownPostBanner, postFooter: rolldownPostFooter, intro: rolldownIntro, outro: rolldownOutro, shimMissingExports: rolldownShimMissingExports } = config.serializer;
|
|
3360
|
+
const { flow: _flow, babel: _babel, swc: _swc, ...rolldownTransform } = config.transformer;
|
|
3351
3361
|
const { treeshake: rolldownTreeshake, minify: rolldownMinify, lazyBarrel: rolldownLazyBarrel, ...rolldownOptimization } = config.optimization;
|
|
3352
|
-
const {
|
|
3362
|
+
const { globalIdentifiers: rolldownGlobalIdentifiers } = config.reactNative;
|
|
3353
3363
|
const { sourcemap: rolldownSourcemap, sourcemapBaseUrl: rolldownSourcemapBaseUrl, sourcemapDebugIds: rolldownSourcemapDebugIds, sourcemapIgnoreList: rolldownSourcemapIgnoreList, sourcemapPathTransform: rolldownSourcemapPathTransform } = config;
|
|
3354
|
-
const
|
|
3355
|
-
const resolvedSourceExtensions = transformSvg ? [...sourceExtensions, "svg"] : sourceExtensions;
|
|
3356
|
-
const resolvedAssetExtensions = transformSvg ? assetExtensions.filter((extension) => extension !== "svg") : assetExtensions;
|
|
3364
|
+
const userPlugins = config.plugins;
|
|
3357
3365
|
const mergedResolveOptions = (0, es_toolkit.merge)({ extensions: getResolveExtensions({
|
|
3358
|
-
sourceExtensions
|
|
3359
|
-
assetExtensions
|
|
3366
|
+
sourceExtensions,
|
|
3367
|
+
assetExtensions,
|
|
3360
3368
|
platform,
|
|
3361
3369
|
preferNativePlatform
|
|
3362
3370
|
}) }, rolldownResolve);
|
|
@@ -3369,29 +3377,20 @@ async function resolveRolldownOptions(context, config, buildOptions, devEngineOp
|
|
|
3369
3377
|
},
|
|
3370
3378
|
define: {
|
|
3371
3379
|
__DEV__: asLiteral(dev),
|
|
3372
|
-
global: asIdentifier(GLOBAL_IDENTIFIER),
|
|
3373
3380
|
"process.env.NODE_ENV": asLiteral(nodeEnvironment(dev)),
|
|
3374
3381
|
"process.env.DEBUG_ROLLIPOP": asLiteral(isDebugEnabled()),
|
|
3382
|
+
...hmrEnabled ? null : { "import.meta.hot": "{}" },
|
|
3375
3383
|
...defineEnvFromObject(env),
|
|
3376
3384
|
...defineEnvFromObject(builtInEnv)
|
|
3377
3385
|
},
|
|
3378
3386
|
helpers: { mode: "Runtime" }
|
|
3379
3387
|
}, rolldownTransform);
|
|
3380
|
-
const
|
|
3381
|
-
|
|
3382
|
-
|
|
3383
|
-
|
|
3384
|
-
|
|
3385
|
-
const
|
|
3386
|
-
switch (config.terminal.status) {
|
|
3387
|
-
case "compat": return new CompatStatusReporter();
|
|
3388
|
-
case "progress": return new ProgressBarStatusReporter(context.id, `[${platform}, ${buildOptions.dev ? "dev" : "prod"}]`, getBuildTotalModules(context.storage, context.id));
|
|
3389
|
-
}
|
|
3390
|
-
})()];
|
|
3391
|
-
const reporterOptions = {
|
|
3392
|
-
initialTotalModules: getBuildTotalModules(context.storage, context.id),
|
|
3393
|
-
reporter: mergeReporters([...defaultReporters, config.reporter].filter(es_toolkit.isNotNil))
|
|
3394
|
-
};
|
|
3388
|
+
const preludePluginOptions = resolvePreludePluginOptions(config);
|
|
3389
|
+
const reactNativePluginOptions = await resolveReactNativePluginOptions(config, context, buildOptions);
|
|
3390
|
+
const babelPluginOptions = resolveBabelPluginOptions(config);
|
|
3391
|
+
const swcPluginOptions = resolveSwcPluginOptions(config);
|
|
3392
|
+
const devServerPluginOptions = resolveDevServerPluginOptions(config, hmrConfig);
|
|
3393
|
+
const reporterPluginOptions = resolveReporterPluginOptions(config, context, buildOptions);
|
|
3395
3394
|
const finalOptions = await applyDangerouslyOverrideOptionsFinalizer(config, {
|
|
3396
3395
|
platform: "neutral",
|
|
3397
3396
|
cwd: config.root,
|
|
@@ -3402,31 +3401,20 @@ async function resolveRolldownOptions(context, config, buildOptions, devEngineOp
|
|
|
3402
3401
|
treeshake: rolldownTreeshake,
|
|
3403
3402
|
external: rolldownExternal,
|
|
3404
3403
|
shimMissingExports: rolldownShimMissingExports,
|
|
3405
|
-
optimization:
|
|
3406
|
-
|
|
3407
|
-
|
|
3404
|
+
optimization: rolldownOptimization,
|
|
3405
|
+
experimental: {
|
|
3406
|
+
lazyBarrel: rolldownLazyBarrel,
|
|
3407
|
+
...isDevServerMode ? { devMode: hmrConfig ? { implement: hmrConfig.runtimeImplement } : false } : null
|
|
3408
3408
|
},
|
|
3409
|
-
experimental: { lazyBarrel: rolldownLazyBarrel },
|
|
3410
3409
|
plugins: withTransformBoundary(context, [
|
|
3411
|
-
preludePlugin(
|
|
3412
|
-
reactNativePlugin(
|
|
3413
|
-
dev,
|
|
3414
|
-
platform,
|
|
3415
|
-
buildType: context.buildType,
|
|
3416
|
-
codegenFilter: codegen.filter,
|
|
3417
|
-
flowFilter: flow.filter,
|
|
3418
|
-
assetsDir: buildOptions.assetsDir,
|
|
3419
|
-
assetExtensions: resolvedAssetExtensions,
|
|
3420
|
-
assetRegistryPath: resolveFrom(config.root, typeof assetRegistryPath === "function" ? await assetRegistryPath(config.root) : assetRegistryPath),
|
|
3421
|
-
hmrClientPath: resolveFrom(config.root, typeof hmrClientPath === "function" ? await hmrClientPath(config.root) : hmrClientPath)
|
|
3422
|
-
}),
|
|
3410
|
+
preludePlugin(preludePluginOptions),
|
|
3411
|
+
reactNativePlugin(reactNativePluginOptions),
|
|
3423
3412
|
jsonPlugin(),
|
|
3424
|
-
|
|
3425
|
-
|
|
3426
|
-
|
|
3427
|
-
reporterPlugin(
|
|
3428
|
-
|
|
3429
|
-
config.plugins
|
|
3413
|
+
babelPlugin(babelPluginOptions),
|
|
3414
|
+
swcPlugin(swcPluginOptions),
|
|
3415
|
+
devServerPlugin(devServerPluginOptions),
|
|
3416
|
+
reporterPlugin(reporterPluginOptions),
|
|
3417
|
+
userPlugins
|
|
3430
3418
|
]),
|
|
3431
3419
|
checks: {
|
|
3432
3420
|
eval: false,
|
|
@@ -3467,6 +3455,78 @@ async function resolveRolldownOptions(context, config, buildOptions, devEngineOp
|
|
|
3467
3455
|
resolveRolldownOptions.cache.set(context.id, finalOptions);
|
|
3468
3456
|
return finalOptions;
|
|
3469
3457
|
}
|
|
3458
|
+
function resolvePreludePluginOptions(config) {
|
|
3459
|
+
return { modulePaths: config.serializer.prelude };
|
|
3460
|
+
}
|
|
3461
|
+
async function resolveReactNativePluginOptions(config, context, buildOptions) {
|
|
3462
|
+
return {
|
|
3463
|
+
projectRoot: config.root,
|
|
3464
|
+
platform: buildOptions.platform,
|
|
3465
|
+
preferNativePlatform: config.resolver.preferNativePlatform,
|
|
3466
|
+
buildType: context.buildType,
|
|
3467
|
+
assetsDir: buildOptions.assetsDir,
|
|
3468
|
+
assetExtensions: config.resolver.assetExtensions,
|
|
3469
|
+
assetRegistryPath: await resolveAssetRegistryPath(config),
|
|
3470
|
+
flowFilter: config.transformer.flow?.filter ?? [],
|
|
3471
|
+
codegenFilter: config.reactNative.codegen?.filter ?? [],
|
|
3472
|
+
builtinPluginConfig: resolveReactNativeBuiltinPluginConfig(config)
|
|
3473
|
+
};
|
|
3474
|
+
}
|
|
3475
|
+
async function resolveAssetRegistryPath(config) {
|
|
3476
|
+
const { assetRegistryPath } = config.reactNative;
|
|
3477
|
+
const path = typeof assetRegistryPath === "function" ? await assetRegistryPath(config.root) : assetRegistryPath;
|
|
3478
|
+
return resolveFrom(config.root, path);
|
|
3479
|
+
}
|
|
3480
|
+
function resolveReactNativeBuiltinPluginConfig(config) {
|
|
3481
|
+
if (!config.experimental?.nativeTransformPipeline) return null;
|
|
3482
|
+
return {
|
|
3483
|
+
envName: config.mode,
|
|
3484
|
+
runtimeTarget: resolveRuntimeTarget(config.runtimeTarget),
|
|
3485
|
+
worklets: resolveWorkletsConfig(config),
|
|
3486
|
+
plugins: []
|
|
3487
|
+
};
|
|
3488
|
+
}
|
|
3489
|
+
function resolveWorkletsConfig(config) {
|
|
3490
|
+
const { worklets } = config.experimental ?? {};
|
|
3491
|
+
if (worklets == null) return;
|
|
3492
|
+
return (0, es_toolkit.merge)({
|
|
3493
|
+
isRelease: config.mode === "production",
|
|
3494
|
+
pluginVersion: resolvePackageJson(config.root, "react-native-worklets")?.version
|
|
3495
|
+
}, worklets);
|
|
3496
|
+
}
|
|
3497
|
+
function resolveBabelPluginOptions(config) {
|
|
3498
|
+
return {
|
|
3499
|
+
useNativeTransformPipeline: config.experimental?.nativeTransformPipeline,
|
|
3500
|
+
transformConfig: config.transformer.babel
|
|
3501
|
+
};
|
|
3502
|
+
}
|
|
3503
|
+
function resolveSwcPluginOptions(config) {
|
|
3504
|
+
return {
|
|
3505
|
+
useNativeTransformPipeline: config.experimental?.nativeTransformPipeline,
|
|
3506
|
+
runtimeTarget: config.runtimeTarget,
|
|
3507
|
+
transformConfig: config.transformer.swc
|
|
3508
|
+
};
|
|
3509
|
+
}
|
|
3510
|
+
function resolveDevServerPluginOptions(config, hmrConfig) {
|
|
3511
|
+
return {
|
|
3512
|
+
cwd: config.root,
|
|
3513
|
+
hmrClientPath: config.reactNative.hmrClientPath,
|
|
3514
|
+
hmrConfig
|
|
3515
|
+
};
|
|
3516
|
+
}
|
|
3517
|
+
function resolveReporterPluginOptions(config, context, buildOptions) {
|
|
3518
|
+
const statusReporter = createStatusReporter(config, context, buildOptions);
|
|
3519
|
+
return {
|
|
3520
|
+
initialTotalModules: getBuildTotalModules(context.storage, context.id),
|
|
3521
|
+
reporter: mergeReporters([statusReporter, config.reporter].filter(es_toolkit.isNotNil))
|
|
3522
|
+
};
|
|
3523
|
+
}
|
|
3524
|
+
function createStatusReporter(config, context, buildOptions) {
|
|
3525
|
+
switch (config.terminal.status) {
|
|
3526
|
+
case "compat": return new CompatStatusReporter();
|
|
3527
|
+
case "progress": return new ProgressBarStatusReporter(context.id, `[${buildOptions.platform}, ${buildOptions.dev ? "dev" : "prod"}]`, getBuildTotalModules(context.storage, context.id));
|
|
3528
|
+
}
|
|
3529
|
+
}
|
|
3470
3530
|
function getResolveExtensions({ platform, sourceExtensions, assetExtensions, preferNativePlatform }) {
|
|
3471
3531
|
const supportedExtensions = [...sourceExtensions, ...assetExtensions];
|
|
3472
3532
|
return [...[platform, preferNativePlatform ? "native" : null].filter(es_toolkit.isNotNil).map((platform) => {
|
|
@@ -3491,13 +3551,11 @@ async function applyDangerouslyOverrideOptionsFinalizer(config, inputOptions, ou
|
|
|
3491
3551
|
output: (0, es_toolkit.merge)(outputOptions, config.dangerously_overrideRolldownOptions?.output ?? {})
|
|
3492
3552
|
};
|
|
3493
3553
|
}
|
|
3494
|
-
function getOverrideOptionsForDevServer(
|
|
3495
|
-
const hmrConfig = resolveHmrConfig(config);
|
|
3554
|
+
function getOverrideOptionsForDevServer(buildOptions) {
|
|
3496
3555
|
return {
|
|
3497
3556
|
input: {
|
|
3498
3557
|
transform: { jsx: { development: true } },
|
|
3499
3558
|
experimental: {
|
|
3500
|
-
devMode: hmrConfig ? { implement: hmrConfig.runtimeImplement } : false,
|
|
3501
3559
|
incrementalBuild: true,
|
|
3502
3560
|
nativeMagicString: true
|
|
3503
3561
|
},
|
|
@@ -3521,7 +3579,7 @@ var Bundler = class Bundler {
|
|
|
3521
3579
|
const resolvedBuildOptions = resolveBuildOptions(config, buildOptions);
|
|
3522
3580
|
const context = Bundler.createContext(buildType, config, resolvedBuildOptions);
|
|
3523
3581
|
const { input = {}, output = {} } = await resolveRolldownOptions(context, config, resolvedBuildOptions, devEngineOptions);
|
|
3524
|
-
const devServerOptions = getOverrideOptionsForDevServer(
|
|
3582
|
+
const devServerOptions = getOverrideOptionsForDevServer(resolvedBuildOptions);
|
|
3525
3583
|
const devEngine = await (0, _rollipop_rolldown_experimental.dev)((0, es_toolkit.merge)(input, devServerOptions.input), (0, es_toolkit.merge)(output, devServerOptions.output), {
|
|
3526
3584
|
watch: config.watcher,
|
|
3527
3585
|
...devEngineOptions
|