@granite-js/mpack 0.1.22 → 0.1.23-next.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/CHANGELOG.md +8 -0
- package/dist/bundler/plugins/transformPlugin/steps/createFlowStripStep.d.ts +2 -0
- package/dist/bundler/plugins/transformPlugin/steps/createFlowStripStep.js +62 -0
- package/dist/bundler/plugins/transformPlugin/steps/createFullyTransformStep.js +1 -1
- package/dist/bundler/plugins/transformPlugin/steps/createTransformCodegenStep.d.ts +2 -0
- package/dist/bundler/plugins/transformPlugin/steps/createTransformCodegenStep.js +70 -0
- package/dist/bundler/plugins/transformPlugin/steps/createTransformToHermesSyntaxStep.d.ts +1 -2
- package/dist/bundler/plugins/transformPlugin/steps/createTransformToHermesSyntaxStep.js +5 -19
- package/dist/bundler/plugins/transformPlugin/transformPlugin.js +11 -5
- package/dist/transformer/AsyncTransformPipeline.js +24 -7
- package/dist/transformer/TransformPipeline.d.ts +17 -12
- package/dist/transformer/TransformPipeline.js +6 -2
- package/dist/vendors/metro/src/lib/ReportableEvent.d.ts +20 -28
- package/dist/vendors/metro/src/lib/TerminalReporter.d.ts +2 -2
- package/package.json +15 -10
- package/src/lib.d.ts +90 -0
- package/src/vendors/metro/src/lib/ReportableEvent.d.ts +20 -28
- package/src/vendors/metro/src/lib/TerminalReporter.d.ts +2 -2
- package/dist/bundler/plugins/transformPlugin/steps/createStripFlowStep.d.ts +0 -6
- package/dist/bundler/plugins/transformPlugin/steps/createStripFlowStep.js +0 -91
package/CHANGELOG.md
CHANGED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
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 __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var createFlowStripStep_exports = {};
|
|
30
|
+
__export(createFlowStripStep_exports, {
|
|
31
|
+
createFlowStripStep: () => createFlowStripStep
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(createFlowStripStep_exports);
|
|
34
|
+
var import_generator = require("@babel/generator");
|
|
35
|
+
var import_flow_remove_types = __toESM(require("flow-remove-types"));
|
|
36
|
+
var HermesParser = __toESM(require("hermes-parser"));
|
|
37
|
+
var import_defineStepName = require("../../../../utils/defineStepName");
|
|
38
|
+
function createFlowStripStep() {
|
|
39
|
+
const flowStripStep = async function flowStrip(code, args) {
|
|
40
|
+
const shouldTransform = args.path.endsWith(".js") || args.path.endsWith(".jsx");
|
|
41
|
+
if (!shouldTransform) {
|
|
42
|
+
return { code };
|
|
43
|
+
}
|
|
44
|
+
try {
|
|
45
|
+
const transformedCode = (0, import_flow_remove_types.default)(code, {});
|
|
46
|
+
const parsedAst = HermesParser.parse(transformedCode.toString(), {
|
|
47
|
+
flow: "all",
|
|
48
|
+
babel: true
|
|
49
|
+
});
|
|
50
|
+
const transformedResult = (0, import_generator.generate)(parsedAst);
|
|
51
|
+
return { code: transformedResult?.code ?? code };
|
|
52
|
+
} catch {
|
|
53
|
+
return { code };
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
(0, import_defineStepName.defineStepName)(flowStripStep, "flow-strip");
|
|
57
|
+
return flowStripStep;
|
|
58
|
+
}
|
|
59
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
60
|
+
0 && (module.exports = {
|
|
61
|
+
createFlowStripStep
|
|
62
|
+
});
|
|
@@ -71,13 +71,13 @@ function createFullyTransformStep({
|
|
|
71
71
|
* @babel/preset-react 포함 필요
|
|
72
72
|
*/
|
|
73
73
|
[require.resolve("@babel/preset-react"), { runtime: "automatic" }],
|
|
74
|
+
[require.resolve("@react-native/babel-preset")],
|
|
74
75
|
...additionalBabelOptions?.presets ?? []
|
|
75
76
|
],
|
|
76
77
|
plugins: [
|
|
77
78
|
/**
|
|
78
79
|
* react-native에서 직접 export 하는 flow 파일 대응을 위해 strip types 추가 필요
|
|
79
80
|
*/
|
|
80
|
-
require.resolve("@babel/plugin-transform-flow-strip-types"),
|
|
81
81
|
[require.resolve("@babel/plugin-proposal-class-properties"), { loose: true }],
|
|
82
82
|
[require.resolve("@babel/plugin-proposal-private-property-in-object"), { loose: true }],
|
|
83
83
|
[require.resolve("@babel/plugin-proposal-private-methods"), { loose: true }],
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
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 __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var createTransformCodegenStep_exports = {};
|
|
30
|
+
__export(createTransformCodegenStep_exports, {
|
|
31
|
+
createTransformCodegenStep: () => createTransformCodegenStep
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(createTransformCodegenStep_exports);
|
|
34
|
+
var import_core = require("@babel/core");
|
|
35
|
+
var import_defineStepName = require("../../../../utils/defineStepName");
|
|
36
|
+
function createTransformCodegenStep() {
|
|
37
|
+
const codegenStep = async function codegen(code, args) {
|
|
38
|
+
const transformedResult = await (0, import_core.transformAsync)(code, {
|
|
39
|
+
test: /(?:^|[\\/])(?:Native\w+|(\w+)NativeComponent)\.[jt]sx?$/,
|
|
40
|
+
filename: args.path,
|
|
41
|
+
minified: false,
|
|
42
|
+
compact: false,
|
|
43
|
+
babelrc: false,
|
|
44
|
+
configFile: false,
|
|
45
|
+
plugins: [
|
|
46
|
+
require.resolve("babel-plugin-syntax-hermes-parser"),
|
|
47
|
+
require.resolve("@babel/plugin-transform-flow-strip-types"),
|
|
48
|
+
[require.resolve("@babel/plugin-syntax-typescript"), false],
|
|
49
|
+
require.resolve("@react-native/babel-plugin-codegen")
|
|
50
|
+
],
|
|
51
|
+
overrides: [
|
|
52
|
+
{
|
|
53
|
+
test: /\.ts$/,
|
|
54
|
+
plugins: [[require.resolve("@babel/plugin-syntax-typescript"), { isTSX: false, allowNamespaces: true }]]
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
test: /\.tsx$/,
|
|
58
|
+
plugins: [[require.resolve("@babel/plugin-syntax-typescript"), { isTSX: true, allowNamespaces: true }]]
|
|
59
|
+
}
|
|
60
|
+
]
|
|
61
|
+
});
|
|
62
|
+
return { code: transformedResult?.code ?? code };
|
|
63
|
+
};
|
|
64
|
+
(0, import_defineStepName.defineStepName)(codegenStep, "transform-codegen");
|
|
65
|
+
return codegenStep;
|
|
66
|
+
}
|
|
67
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
68
|
+
0 && (module.exports = {
|
|
69
|
+
createTransformCodegenStep
|
|
70
|
+
});
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import type { BuildConfig } from '@granite-js/plugin-core';
|
|
2
2
|
import { AsyncTransformStep } from '../../../../transformer/TransformPipeline';
|
|
3
|
-
interface TransformToHermesSyntaxStepConfig {
|
|
3
|
+
export interface TransformToHermesSyntaxStepConfig {
|
|
4
4
|
dev: boolean;
|
|
5
5
|
additionalSwcOptions?: BuildConfig['swc'];
|
|
6
6
|
}
|
|
7
7
|
export declare function createTransformToHermesSyntaxStep({ dev, additionalSwcOptions, }: TransformToHermesSyntaxStepConfig): AsyncTransformStep;
|
|
8
|
-
export {};
|
|
@@ -36,17 +36,6 @@ var swc = __toESM(require("@swc/core"));
|
|
|
36
36
|
var import_es_toolkit = require("es-toolkit");
|
|
37
37
|
var import_defineStepName = require("../../../../utils/defineStepName");
|
|
38
38
|
var import_swc = require("../../shared/swc");
|
|
39
|
-
function getParserConfig(filepath) {
|
|
40
|
-
return /\.tsx?$/.test(filepath) ? {
|
|
41
|
-
syntax: "typescript",
|
|
42
|
-
tsx: true,
|
|
43
|
-
dynamicImport: true
|
|
44
|
-
} : {
|
|
45
|
-
syntax: "ecmascript",
|
|
46
|
-
jsx: true,
|
|
47
|
-
exportDefaultFrom: true
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
39
|
function createTransformToHermesSyntaxStep({
|
|
51
40
|
dev,
|
|
52
41
|
additionalSwcOptions = {}
|
|
@@ -58,7 +47,11 @@ function createTransformToHermesSyntaxStep({
|
|
|
58
47
|
isModule: true,
|
|
59
48
|
jsc: {
|
|
60
49
|
...import_swc.swcHelperOptimizationRules.jsc,
|
|
61
|
-
parser:
|
|
50
|
+
parser: {
|
|
51
|
+
syntax: "typescript",
|
|
52
|
+
tsx: true,
|
|
53
|
+
dynamicImport: true
|
|
54
|
+
},
|
|
62
55
|
target: "es5",
|
|
63
56
|
keepClassNames: true,
|
|
64
57
|
transform: {
|
|
@@ -69,13 +62,6 @@ function createTransformToHermesSyntaxStep({
|
|
|
69
62
|
},
|
|
70
63
|
experimental: { plugins },
|
|
71
64
|
loose: false,
|
|
72
|
-
/**
|
|
73
|
-
* 타입정의가 없지만 실제로는 동작하는 것이 스펙
|
|
74
|
-
*
|
|
75
|
-
* @see {@link https://github.com/swc-project/swc/blob/v1.4.10/crates/swc_ecma_transforms_base/src/assumptions.rs#L11}
|
|
76
|
-
*/
|
|
77
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
78
|
-
// @ts-ignore
|
|
79
65
|
assumptions: {
|
|
80
66
|
setPublicClassFields: true,
|
|
81
67
|
privateFieldsAsProperties: true
|
|
@@ -35,8 +35,9 @@ var import_assert = __toESM(require("assert"));
|
|
|
35
35
|
var fs = __toESM(require("fs/promises"));
|
|
36
36
|
var preludeScript = __toESM(require("./helpers/preludeScript"));
|
|
37
37
|
var import_createCacheSteps = require("./steps/createCacheSteps");
|
|
38
|
+
var import_createFlowStripStep = require("./steps/createFlowStripStep");
|
|
38
39
|
var import_createFullyTransformStep = require("./steps/createFullyTransformStep");
|
|
39
|
-
var
|
|
40
|
+
var import_createTransformCodegenStep = require("./steps/createTransformCodegenStep");
|
|
40
41
|
var import_createTransformToHermesSyntaxStep = require("./steps/createTransformToHermesSyntaxStep");
|
|
41
42
|
var import_performance = require("../../../performance");
|
|
42
43
|
var import_transformer = require("../../../transformer");
|
|
@@ -60,10 +61,15 @@ function transformPlugin({ context, ...options }) {
|
|
|
60
61
|
code = await options.transformAsync(args.path, code);
|
|
61
62
|
}
|
|
62
63
|
return { code };
|
|
63
|
-
}).addStep(
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
64
|
+
}).addStep({
|
|
65
|
+
if: ({ path, code }) => babel?.conditions?.some((cond) => cond(code, path)) ?? false,
|
|
66
|
+
then: (0, import_createFullyTransformStep.createFullyTransformStep)({ dev, additionalBabelOptions: babel }),
|
|
67
|
+
stopAfter: true
|
|
68
|
+
}).addStep({
|
|
69
|
+
if: ({ path }) => /(?:^|[\\/])(?:Native\w+|(\w+)NativeComponent)\.[jt]sx?$/.test(path),
|
|
70
|
+
then: (0, import_createTransformCodegenStep.createTransformCodegenStep)(),
|
|
71
|
+
else: (0, import_createFlowStripStep.createFlowStripStep)()
|
|
72
|
+
}).addStep((0, import_createTransformToHermesSyntaxStep.createTransformToHermesSyntaxStep)({ dev, additionalSwcOptions: swc })).afterStep(cacheSteps.afterTransform);
|
|
67
73
|
preludeScript.registerEntryPointMarker(build);
|
|
68
74
|
preludeScript.registerPreludeScriptResolver(build);
|
|
69
75
|
build.onLoad({ filter: sourceRegExp }, async (args) => {
|
|
@@ -33,19 +33,36 @@ class AsyncTransformPipeline extends import_TransformPipeline.TransformPipeline
|
|
|
33
33
|
return this._afterStep ? this._afterStep(code2, args2, context2) : Promise.resolve({ code: code2, done: true });
|
|
34
34
|
};
|
|
35
35
|
let result = await before(code, args, context);
|
|
36
|
-
for await (const
|
|
36
|
+
for await (const entry of this.steps) {
|
|
37
37
|
if (result.done) {
|
|
38
38
|
break;
|
|
39
39
|
}
|
|
40
|
-
if (
|
|
40
|
+
if (entry.type === "normal" && entry.step) {
|
|
41
41
|
let trace;
|
|
42
|
-
if (typeof step.name === "string") {
|
|
43
|
-
trace = import_performance.Performance.trace(`step-${step.name}`, { detail: { file: args.path } });
|
|
42
|
+
if (typeof entry.step.name === "string") {
|
|
43
|
+
trace = import_performance.Performance.trace(`step-${entry.step.name}`, { detail: { file: args.path } });
|
|
44
44
|
}
|
|
45
|
-
result = await step(result.code, args, context);
|
|
45
|
+
result = await entry.step(result.code, args, context);
|
|
46
46
|
trace?.stop();
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
} else if (entry.type === "conditional" && entry.condition) {
|
|
48
|
+
const condition = entry.condition;
|
|
49
|
+
if (condition.if({ path: args.path, code: result.code })) {
|
|
50
|
+
let trace;
|
|
51
|
+
if (typeof condition.then.name === "string") {
|
|
52
|
+
trace = import_performance.Performance.trace(`step-${condition.then.name}`, { detail: { file: args.path } });
|
|
53
|
+
}
|
|
54
|
+
result = await condition.then(result.code, args, context);
|
|
55
|
+
trace?.stop();
|
|
56
|
+
if (condition.stopAfter) {
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
} else if (condition.else) {
|
|
60
|
+
let trace;
|
|
61
|
+
if (typeof condition.else.name === "string") {
|
|
62
|
+
trace = import_performance.Performance.trace(`step-${condition.else.name}`, { detail: { file: args.path } });
|
|
63
|
+
}
|
|
64
|
+
result = await condition.else(result.code, args, context);
|
|
65
|
+
trace?.stop();
|
|
49
66
|
}
|
|
50
67
|
}
|
|
51
68
|
}
|
|
@@ -13,24 +13,29 @@ interface TransformStep<TransformResult> {
|
|
|
13
13
|
(code: string, args: TransformStepArgs, context: TransformStepContext): TransformResult;
|
|
14
14
|
name?: string;
|
|
15
15
|
}
|
|
16
|
-
interface TransformStepConfig {
|
|
17
|
-
/**
|
|
18
|
-
* step 을 실행하기 위한 조건 (기본값: 항상 실행)
|
|
19
|
-
*/
|
|
20
|
-
conditions?: Array<(code: string, path: string) => boolean>;
|
|
21
|
-
/**
|
|
22
|
-
* 현재 step 이 실행된 경우 done 처리 여부 (기본값: false)
|
|
23
|
-
*/
|
|
24
|
-
skipOtherSteps?: boolean;
|
|
25
|
-
}
|
|
26
16
|
export type AsyncTransformStep = TransformStep<Promise<TransformStepResult>>;
|
|
17
|
+
export interface ConditionalStep {
|
|
18
|
+
if: (args: {
|
|
19
|
+
path: string;
|
|
20
|
+
code: string;
|
|
21
|
+
}) => boolean;
|
|
22
|
+
then: AsyncTransformStep;
|
|
23
|
+
else?: AsyncTransformStep;
|
|
24
|
+
stopAfter?: boolean;
|
|
25
|
+
}
|
|
26
|
+
export type StepInput = AsyncTransformStep | ConditionalStep;
|
|
27
|
+
interface StepEntry {
|
|
28
|
+
type: 'normal' | 'conditional';
|
|
29
|
+
step?: AsyncTransformStep;
|
|
30
|
+
condition?: ConditionalStep;
|
|
31
|
+
}
|
|
27
32
|
export declare abstract class TransformPipeline<Step extends TransformStep<unknown>> {
|
|
28
33
|
protected _beforeStep?: Step;
|
|
29
34
|
protected _afterStep?: Step;
|
|
30
|
-
protected steps:
|
|
35
|
+
protected steps: StepEntry[];
|
|
31
36
|
beforeStep(step: Step): this;
|
|
32
37
|
afterStep(step: Step): this;
|
|
33
|
-
addStep(step:
|
|
38
|
+
addStep(step: StepInput): this;
|
|
34
39
|
getStepContext(args: TransformStepArgs): Promise<TransformStepContext>;
|
|
35
40
|
abstract transform(code: string, args: TransformStepArgs): ReturnType<Step>;
|
|
36
41
|
}
|
|
@@ -46,8 +46,12 @@ class TransformPipeline {
|
|
|
46
46
|
this._afterStep = step;
|
|
47
47
|
return this;
|
|
48
48
|
}
|
|
49
|
-
addStep(step
|
|
50
|
-
|
|
49
|
+
addStep(step) {
|
|
50
|
+
if (typeof step === "function") {
|
|
51
|
+
this.steps.push({ type: "normal", step });
|
|
52
|
+
} else {
|
|
53
|
+
this.steps.push({ type: "conditional", condition: step });
|
|
54
|
+
}
|
|
51
55
|
return this;
|
|
52
56
|
}
|
|
53
57
|
async getStepContext(args) {
|
|
@@ -8,24 +8,24 @@ interface BundleDetails {
|
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
type WatcherStatus =
|
|
11
|
-
| {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
| {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
| {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
};
|
|
11
|
+
| {
|
|
12
|
+
type: 'watchman_slow_command';
|
|
13
|
+
timeElapsed: number;
|
|
14
|
+
command: 'watch-project' | 'query';
|
|
15
|
+
}
|
|
16
|
+
| {
|
|
17
|
+
type: 'watchman_slow_command_complete';
|
|
18
|
+
timeElapsed: number;
|
|
19
|
+
command: 'watch-project' | 'query';
|
|
20
|
+
}
|
|
21
|
+
| {
|
|
22
|
+
type: 'watchman_warning';
|
|
23
|
+
warning: unknown;
|
|
24
|
+
command: 'watch-project' | 'query';
|
|
25
|
+
};
|
|
26
26
|
|
|
27
27
|
type HealthCheckResult =
|
|
28
|
-
| {type: 'error'; timeout: number; error: Error; watcher: string | null}
|
|
28
|
+
| { type: 'error'; timeout: number; error: Error; watcher: string | null }
|
|
29
29
|
| {
|
|
30
30
|
type: 'success';
|
|
31
31
|
timeout: number;
|
|
@@ -80,7 +80,7 @@ export type ReportableEvent =
|
|
|
80
80
|
type: 'dep_graph_loading';
|
|
81
81
|
hasReducedPerformance: boolean;
|
|
82
82
|
}
|
|
83
|
-
| {type: 'dep_graph_loaded'}
|
|
83
|
+
| { type: 'dep_graph_loaded' }
|
|
84
84
|
| {
|
|
85
85
|
buildID: string;
|
|
86
86
|
type: 'bundle_transform_progressed';
|
|
@@ -95,7 +95,7 @@ export type ReportableEvent =
|
|
|
95
95
|
type: 'cache_write_error';
|
|
96
96
|
error: Error;
|
|
97
97
|
}
|
|
98
|
-
| {type: 'transform_cache_reset'}
|
|
98
|
+
| { type: 'transform_cache_reset' }
|
|
99
99
|
| {
|
|
100
100
|
type: 'worker_stdout_chunk';
|
|
101
101
|
chunk: string;
|
|
@@ -110,15 +110,7 @@ export type ReportableEvent =
|
|
|
110
110
|
}
|
|
111
111
|
| {
|
|
112
112
|
type: 'client_log';
|
|
113
|
-
level:
|
|
114
|
-
| 'trace'
|
|
115
|
-
| 'info'
|
|
116
|
-
| 'warn'
|
|
117
|
-
| 'log'
|
|
118
|
-
| 'group'
|
|
119
|
-
| 'groupCollapsed'
|
|
120
|
-
| 'groupEnd'
|
|
121
|
-
| 'debug';
|
|
113
|
+
level: 'trace' | 'info' | 'warn' | 'log' | 'group' | 'groupCollapsed' | 'groupEnd' | 'debug';
|
|
122
114
|
data: Array<unknown>;
|
|
123
115
|
mode: 'BRIDGE' | 'NOBRIDGE';
|
|
124
116
|
}
|
|
@@ -149,4 +141,4 @@ export type ReportableEvent =
|
|
|
149
141
|
| {
|
|
150
142
|
type: 'watcher_status';
|
|
151
143
|
status: WatcherStatus;
|
|
152
|
-
};
|
|
144
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ReportableEvent } from
|
|
1
|
+
import type { ReportableEvent } from './ReportableEvent';
|
|
2
2
|
type Terminal = any;
|
|
3
3
|
type TerminalReportableEvent =
|
|
4
4
|
| ReportableEvent
|
|
@@ -15,4 +15,4 @@ declare class TerminalReporter {
|
|
|
15
15
|
update(event: TerminalReportableEvent): void;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
export default TerminalReporter;
|
|
18
|
+
export default TerminalReporter;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@granite-js/mpack",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.23-next.0",
|
|
4
4
|
"description": "A bundler for Granite apps",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
"eslint": "9.7.0",
|
|
63
63
|
"execa": "^5.0.0",
|
|
64
64
|
"fast-glob": "^3.3.2",
|
|
65
|
-
"flow-remove-types": "^2.
|
|
65
|
+
"flow-remove-types": "^2.279.0",
|
|
66
66
|
"prettier-2": "npm:prettier@^2",
|
|
67
67
|
"ts-prune": "^0.10.3",
|
|
68
68
|
"typescript": "5.8.3",
|
|
@@ -76,29 +76,33 @@
|
|
|
76
76
|
"@babel/plugin-proposal-class-properties": "7.18.6",
|
|
77
77
|
"@babel/plugin-proposal-private-methods": "7.18.6",
|
|
78
78
|
"@babel/plugin-proposal-private-property-in-object": "7.21.11",
|
|
79
|
-
"@babel/plugin-
|
|
79
|
+
"@babel/plugin-syntax-typescript": "^7.27.1",
|
|
80
|
+
"@babel/plugin-transform-flow-strip-types": "npm:7.27.1",
|
|
80
81
|
"@babel/preset-env": "7.23.3",
|
|
81
82
|
"@babel/preset-react": "7.23.3",
|
|
82
|
-
"@babel/preset-typescript": "7.
|
|
83
|
+
"@babel/preset-typescript": "7.27.1",
|
|
83
84
|
"@babel/template": "^7.0.0",
|
|
84
85
|
"@babel/traverse": "^7.14.0",
|
|
85
86
|
"@babel/types": "^7.0.0",
|
|
86
87
|
"@fastify/static": "7.0.1",
|
|
87
|
-
"@granite-js/devtools-frontend": "0.1.
|
|
88
|
-
"@granite-js/plugin-core": "0.1.
|
|
89
|
-
"@granite-js/utils": "0.1.
|
|
88
|
+
"@granite-js/devtools-frontend": "0.1.23-next.0",
|
|
89
|
+
"@granite-js/plugin-core": "0.1.23-next.0",
|
|
90
|
+
"@granite-js/utils": "0.1.23-next.0",
|
|
90
91
|
"@inquirer/prompts": "^7.2.3",
|
|
91
92
|
"@react-native-community/cli-plugin-metro": "11.3.7",
|
|
92
93
|
"@react-native-community/cli-server-api": "11.3.7",
|
|
93
94
|
"@react-native-community/cli-tools": "11.3.7",
|
|
95
|
+
"@react-native/babel-plugin-codegen": "npm:0.81.0",
|
|
96
|
+
"@react-native/babel-preset": "npm:0.81.0",
|
|
94
97
|
"@react-native/dev-middleware": "0.73.8",
|
|
95
98
|
"@shopify/semaphore": "^3.1.0",
|
|
96
|
-
"@swc/core": "1.
|
|
97
|
-
"@swc/helpers": "0.5.
|
|
99
|
+
"@swc/core": "npm:1.13.3",
|
|
100
|
+
"@swc/helpers": "npm:0.5.17",
|
|
98
101
|
"absolute-path": "^0.0.0",
|
|
99
102
|
"accepts": "^1.3.7",
|
|
100
103
|
"assert": "2.1.0",
|
|
101
104
|
"async": "^3.2.2",
|
|
105
|
+
"babel-plugin-syntax-hermes-parser": "^0.31.0",
|
|
102
106
|
"babel-preset-fbjs": "^3.4.0",
|
|
103
107
|
"browserify-zlib": "0.2.0",
|
|
104
108
|
"buffer": "6.0.3",
|
|
@@ -119,7 +123,7 @@
|
|
|
119
123
|
"frogress-bar": "^0.1.0",
|
|
120
124
|
"fs-extra": "^1.0.0",
|
|
121
125
|
"graceful-fs": "^4.2.4",
|
|
122
|
-
"hermes-parser": "0.
|
|
126
|
+
"hermes-parser": "0.31.2",
|
|
123
127
|
"https-browserify": "1.0.0",
|
|
124
128
|
"image-size": "^0.6.0",
|
|
125
129
|
"invariant": "^2.2.4",
|
|
@@ -143,6 +147,7 @@
|
|
|
143
147
|
"mime-types": "^2.1.27",
|
|
144
148
|
"node-fetch": "^2.2.0",
|
|
145
149
|
"nullthrows": "^1.1.1",
|
|
150
|
+
"oxc-transform": "^0.82.1",
|
|
146
151
|
"path-browserify": "1.0.1",
|
|
147
152
|
"react-native-devtools-standalone": "^0.4.1",
|
|
148
153
|
"rimraf": "^2.5.4",
|
package/src/lib.d.ts
CHANGED
|
@@ -59,3 +59,93 @@ declare module 'metro-react-native-babel-transformer' {
|
|
|
59
59
|
|
|
60
60
|
export default babelTransformer;
|
|
61
61
|
}
|
|
62
|
+
|
|
63
|
+
declare module 'flow-remove-types' {
|
|
64
|
+
declare const removeTypes: (
|
|
65
|
+
code: string,
|
|
66
|
+
options: {
|
|
67
|
+
all?: boolean;
|
|
68
|
+
ignoreUninitializedFields?: boolean;
|
|
69
|
+
pretty?: boolean;
|
|
70
|
+
removeEmptyImports?: boolean;
|
|
71
|
+
}
|
|
72
|
+
) => {
|
|
73
|
+
toString(): string;
|
|
74
|
+
generateMap(): {
|
|
75
|
+
version: number;
|
|
76
|
+
sources: string[];
|
|
77
|
+
names: string[];
|
|
78
|
+
mappings: string;
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
export = removeTypes;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
declare module 'hermes-parser' {
|
|
85
|
+
export type ParserOptions = {
|
|
86
|
+
allowReturnOutsideFunction?: boolean;
|
|
87
|
+
babel?: boolean;
|
|
88
|
+
flow?: 'all' | 'detect';
|
|
89
|
+
enableExperimentalComponentSyntax?: boolean;
|
|
90
|
+
enableExperimentalFlowMatchSyntax?: boolean;
|
|
91
|
+
reactRuntimeTarget?: '18' | '19';
|
|
92
|
+
sourceFilename?: string;
|
|
93
|
+
sourceType?: 'module' | 'script' | 'unambiguous';
|
|
94
|
+
tokens?: boolean;
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
export const ParserOptionsKeys: ReadonlySet<keyof ParserOptions>;
|
|
98
|
+
|
|
99
|
+
export type HermesPosition = {
|
|
100
|
+
/** >= 1 */
|
|
101
|
+
line: number;
|
|
102
|
+
/** >= 0 */
|
|
103
|
+
column: number;
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
export type HermesSourceLocation = {
|
|
107
|
+
start?: HermesPosition;
|
|
108
|
+
end?: HermesPosition;
|
|
109
|
+
rangeStart?: number;
|
|
110
|
+
rangeEnd?: number;
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
export type HermesNode = {
|
|
114
|
+
type: string;
|
|
115
|
+
[key: string]: any;
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
export type HermesToken = {
|
|
119
|
+
type:
|
|
120
|
+
| 'Boolean'
|
|
121
|
+
| 'Identifier'
|
|
122
|
+
| 'Keyword'
|
|
123
|
+
| 'Null'
|
|
124
|
+
| 'Numeric'
|
|
125
|
+
| 'BigInt'
|
|
126
|
+
| 'Punctuator'
|
|
127
|
+
| 'String'
|
|
128
|
+
| 'RegularExpression'
|
|
129
|
+
| 'Template'
|
|
130
|
+
| 'JSXText';
|
|
131
|
+
loc: HermesSourceLocation;
|
|
132
|
+
value?: string | null;
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
export type HermesComment = {
|
|
136
|
+
type: 'CommentLine' | 'CommentBlock' | 'InterpreterDirective';
|
|
137
|
+
loc: HermesSourceLocation;
|
|
138
|
+
value?: string | null;
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
export type HermesProgram = {
|
|
142
|
+
type: 'Program';
|
|
143
|
+
loc: HermesSourceLocation;
|
|
144
|
+
body: Array<HermesNode | null>;
|
|
145
|
+
comments: Array<HermesComment>;
|
|
146
|
+
tokens?: Array<HermesToken>;
|
|
147
|
+
interpreter?: HermesComment | null;
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
export function parse(code: string, options?: ParserOptions): HermesProgram;
|
|
151
|
+
}
|
|
@@ -8,24 +8,24 @@ interface BundleDetails {
|
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
type WatcherStatus =
|
|
11
|
-
| {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
| {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
| {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
};
|
|
11
|
+
| {
|
|
12
|
+
type: 'watchman_slow_command';
|
|
13
|
+
timeElapsed: number;
|
|
14
|
+
command: 'watch-project' | 'query';
|
|
15
|
+
}
|
|
16
|
+
| {
|
|
17
|
+
type: 'watchman_slow_command_complete';
|
|
18
|
+
timeElapsed: number;
|
|
19
|
+
command: 'watch-project' | 'query';
|
|
20
|
+
}
|
|
21
|
+
| {
|
|
22
|
+
type: 'watchman_warning';
|
|
23
|
+
warning: unknown;
|
|
24
|
+
command: 'watch-project' | 'query';
|
|
25
|
+
};
|
|
26
26
|
|
|
27
27
|
type HealthCheckResult =
|
|
28
|
-
| {type: 'error'; timeout: number; error: Error; watcher: string | null}
|
|
28
|
+
| { type: 'error'; timeout: number; error: Error; watcher: string | null }
|
|
29
29
|
| {
|
|
30
30
|
type: 'success';
|
|
31
31
|
timeout: number;
|
|
@@ -80,7 +80,7 @@ export type ReportableEvent =
|
|
|
80
80
|
type: 'dep_graph_loading';
|
|
81
81
|
hasReducedPerformance: boolean;
|
|
82
82
|
}
|
|
83
|
-
| {type: 'dep_graph_loaded'}
|
|
83
|
+
| { type: 'dep_graph_loaded' }
|
|
84
84
|
| {
|
|
85
85
|
buildID: string;
|
|
86
86
|
type: 'bundle_transform_progressed';
|
|
@@ -95,7 +95,7 @@ export type ReportableEvent =
|
|
|
95
95
|
type: 'cache_write_error';
|
|
96
96
|
error: Error;
|
|
97
97
|
}
|
|
98
|
-
| {type: 'transform_cache_reset'}
|
|
98
|
+
| { type: 'transform_cache_reset' }
|
|
99
99
|
| {
|
|
100
100
|
type: 'worker_stdout_chunk';
|
|
101
101
|
chunk: string;
|
|
@@ -110,15 +110,7 @@ export type ReportableEvent =
|
|
|
110
110
|
}
|
|
111
111
|
| {
|
|
112
112
|
type: 'client_log';
|
|
113
|
-
level:
|
|
114
|
-
| 'trace'
|
|
115
|
-
| 'info'
|
|
116
|
-
| 'warn'
|
|
117
|
-
| 'log'
|
|
118
|
-
| 'group'
|
|
119
|
-
| 'groupCollapsed'
|
|
120
|
-
| 'groupEnd'
|
|
121
|
-
| 'debug';
|
|
113
|
+
level: 'trace' | 'info' | 'warn' | 'log' | 'group' | 'groupCollapsed' | 'groupEnd' | 'debug';
|
|
122
114
|
data: Array<unknown>;
|
|
123
115
|
mode: 'BRIDGE' | 'NOBRIDGE';
|
|
124
116
|
}
|
|
@@ -149,4 +141,4 @@ export type ReportableEvent =
|
|
|
149
141
|
| {
|
|
150
142
|
type: 'watcher_status';
|
|
151
143
|
status: WatcherStatus;
|
|
152
|
-
};
|
|
144
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ReportableEvent } from
|
|
1
|
+
import type { ReportableEvent } from './ReportableEvent';
|
|
2
2
|
type Terminal = any;
|
|
3
3
|
type TerminalReportableEvent =
|
|
4
4
|
| ReportableEvent
|
|
@@ -15,4 +15,4 @@ declare class TerminalReporter {
|
|
|
15
15
|
update(event: TerminalReportableEvent): void;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
export default TerminalReporter;
|
|
18
|
+
export default TerminalReporter;
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
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 __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
var createStripFlowStep_exports = {};
|
|
30
|
-
__export(createStripFlowStep_exports, {
|
|
31
|
-
createStripFlowStep: () => createStripFlowStep
|
|
32
|
-
});
|
|
33
|
-
module.exports = __toCommonJS(createStripFlowStep_exports);
|
|
34
|
-
var import_path = __toESM(require("path"));
|
|
35
|
-
var babel = __toESM(require("@babel/core"));
|
|
36
|
-
var sucrase = __toESM(require("sucrase"));
|
|
37
|
-
var import_defineStepName = require("../../../../utils/defineStepName");
|
|
38
|
-
function createStripFlowStep(config) {
|
|
39
|
-
const stripImportTypeofStatements = (code) => {
|
|
40
|
-
return code.split("\n").filter((line) => !line.startsWith("import typeof ")).join("\n");
|
|
41
|
-
};
|
|
42
|
-
const stripFlowStep = async function stripFlow(code, args) {
|
|
43
|
-
const shouldTransform = args.path.endsWith(".js");
|
|
44
|
-
if (!shouldTransform) {
|
|
45
|
-
return { code };
|
|
46
|
-
}
|
|
47
|
-
try {
|
|
48
|
-
const result = sucrase.transform(code, {
|
|
49
|
-
transforms: ["flow", "jsx"],
|
|
50
|
-
jsxRuntime: "preserve",
|
|
51
|
-
disableESTransforms: true
|
|
52
|
-
});
|
|
53
|
-
return { code: stripImportTypeofStatements(result.code) };
|
|
54
|
-
} catch {
|
|
55
|
-
const result = await babel.transformAsync(code, {
|
|
56
|
-
configFile: false,
|
|
57
|
-
minified: false,
|
|
58
|
-
compact: false,
|
|
59
|
-
babelrc: false,
|
|
60
|
-
envName: config.dev ? "development" : "production",
|
|
61
|
-
caller: {
|
|
62
|
-
name: "mpack-strip-flow-plugin",
|
|
63
|
-
supportsStaticESM: true
|
|
64
|
-
},
|
|
65
|
-
presets: [
|
|
66
|
-
/**
|
|
67
|
-
* flow 구문과 jsx 구문이 함께 존재하는 경우가 있기에 preset-react 사용
|
|
68
|
-
*/
|
|
69
|
-
[require.resolve("@babel/preset-react"), { runtime: "automatic" }]
|
|
70
|
-
],
|
|
71
|
-
plugins: [
|
|
72
|
-
/**
|
|
73
|
-
* flow 구문 변환을 위해 flow-strip-types 사용
|
|
74
|
-
*/
|
|
75
|
-
require.resolve("@babel/plugin-transform-flow-strip-types")
|
|
76
|
-
],
|
|
77
|
-
filename: import_path.default.basename(args.path)
|
|
78
|
-
});
|
|
79
|
-
if (result?.code != null) {
|
|
80
|
-
return { code: result.code };
|
|
81
|
-
}
|
|
82
|
-
throw new Error("babel transform result is null");
|
|
83
|
-
}
|
|
84
|
-
};
|
|
85
|
-
(0, import_defineStepName.defineStepName)(stripFlowStep, "strip-flow");
|
|
86
|
-
return stripFlowStep;
|
|
87
|
-
}
|
|
88
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
89
|
-
0 && (module.exports = {
|
|
90
|
-
createStripFlowStep
|
|
91
|
-
});
|