@ecrindigital/facetpack 0.1.1 → 0.1.2

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.
@@ -0,0 +1,68 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropNames = Object.getOwnPropertyNames;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __moduleCache = /* @__PURE__ */ new WeakMap;
6
+ var __toCommonJS = (from) => {
7
+ var entry = __moduleCache.get(from), desc;
8
+ if (entry)
9
+ return entry;
10
+ entry = __defProp({}, "__esModule", { value: true });
11
+ if (from && typeof from === "object" || typeof from === "function")
12
+ __getOwnPropNames(from).map((key) => !__hasOwnProp.call(entry, key) && __defProp(entry, key, {
13
+ get: () => from[key],
14
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
15
+ }));
16
+ __moduleCache.set(from, entry);
17
+ return entry;
18
+ };
19
+ var __export = (target, all) => {
20
+ for (var name in all)
21
+ __defProp(target, name, {
22
+ get: all[name],
23
+ enumerable: true,
24
+ configurable: true,
25
+ set: (newValue) => all[name] = () => newValue
26
+ });
27
+ };
28
+
29
+ // src/minifier.ts
30
+ var exports_minifier = {};
31
+ __export(exports_minifier, {
32
+ minifyCode: () => minifyCode,
33
+ minify: () => minify,
34
+ default: () => minifier_default
35
+ });
36
+ module.exports = __toCommonJS(exports_minifier);
37
+ var import_facetpack_native = require("@ecrindigital/facetpack-native");
38
+ function minify(input) {
39
+ const options = {
40
+ compress: input.config.compress ?? true,
41
+ mangle: input.config.mangle ?? true,
42
+ keepFnames: input.config.keep_fnames ?? false,
43
+ dropConsole: input.config.drop_console ?? false,
44
+ dropDebugger: input.config.drop_debugger ?? true,
45
+ sourcemap: input.map !== undefined
46
+ };
47
+ const result = import_facetpack_native.minifySync(input.code, input.filename, options);
48
+ return {
49
+ code: result.code,
50
+ map: result.map ?? undefined
51
+ };
52
+ }
53
+ function minifyCode(code, filename, options) {
54
+ const nativeOptions = {
55
+ compress: options?.compress ?? true,
56
+ mangle: options?.mangle ?? true,
57
+ keepFnames: options?.keep_fnames ?? false,
58
+ dropConsole: options?.drop_console ?? false,
59
+ dropDebugger: options?.drop_debugger ?? true,
60
+ sourcemap: false
61
+ };
62
+ const result = import_facetpack_native.minifySync(code, filename, nativeOptions);
63
+ return {
64
+ code: result.code,
65
+ map: result.map ?? undefined
66
+ };
67
+ }
68
+ var minifier_default = minify;
@@ -0,0 +1,22 @@
1
+ export interface MinifierConfig {
2
+ compress?: boolean;
3
+ mangle?: boolean;
4
+ keep_fnames?: boolean;
5
+ drop_console?: boolean;
6
+ drop_debugger?: boolean;
7
+ }
8
+ interface MetroMinifyInput {
9
+ code: string;
10
+ map?: string;
11
+ filename: string;
12
+ reserved?: string[];
13
+ config: MinifierConfig;
14
+ }
15
+ interface MetroMinifyOutput {
16
+ code: string;
17
+ map?: string;
18
+ }
19
+ export declare function minify(input: MetroMinifyInput): MetroMinifyOutput;
20
+ export declare function minifyCode(code: string, filename: string, options?: MinifierConfig): MetroMinifyOutput;
21
+ export default minify;
22
+ //# sourceMappingURL=minifier.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"minifier.d.ts","sourceRoot":"","sources":["../src/minifier.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,aAAa,CAAC,EAAE,OAAO,CAAA;CACxB;AAED,UAAU,gBAAgB;IACxB,IAAI,EAAE,MAAM,CAAA;IACZ,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,QAAQ,EAAE,MAAM,CAAA;IAChB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAA;IACnB,MAAM,EAAE,cAAc,CAAA;CACvB;AAED,UAAU,iBAAiB;IACzB,IAAI,EAAE,MAAM,CAAA;IACZ,GAAG,CAAC,EAAE,MAAM,CAAA;CACb;AAED,wBAAgB,MAAM,CAAC,KAAK,EAAE,gBAAgB,GAAG,iBAAiB,CAgBjE;AAED,wBAAgB,UAAU,CACxB,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,cAAc,GACvB,iBAAiB,CAgBnB;AAED,eAAe,MAAM,CAAA"}
@@ -0,0 +1,41 @@
1
+ import { createRequire } from "node:module";
2
+ var __require = /* @__PURE__ */ createRequire(import.meta.url);
3
+
4
+ // src/minifier.ts
5
+ import { minifySync } from "@ecrindigital/facetpack-native";
6
+ function minify(input) {
7
+ const options = {
8
+ compress: input.config.compress ?? true,
9
+ mangle: input.config.mangle ?? true,
10
+ keepFnames: input.config.keep_fnames ?? false,
11
+ dropConsole: input.config.drop_console ?? false,
12
+ dropDebugger: input.config.drop_debugger ?? true,
13
+ sourcemap: input.map !== undefined
14
+ };
15
+ const result = minifySync(input.code, input.filename, options);
16
+ return {
17
+ code: result.code,
18
+ map: result.map ?? undefined
19
+ };
20
+ }
21
+ function minifyCode(code, filename, options) {
22
+ const nativeOptions = {
23
+ compress: options?.compress ?? true,
24
+ mangle: options?.mangle ?? true,
25
+ keepFnames: options?.keep_fnames ?? false,
26
+ dropConsole: options?.drop_console ?? false,
27
+ dropDebugger: options?.drop_debugger ?? true,
28
+ sourcemap: false
29
+ };
30
+ const result = minifySync(code, filename, nativeOptions);
31
+ return {
32
+ code: result.code,
33
+ map: result.map ?? undefined
34
+ };
35
+ }
36
+ var minifier_default = minify;
37
+ export {
38
+ minifyCode,
39
+ minify,
40
+ minifier_default as default
41
+ };
@@ -0,0 +1,196 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropNames = Object.getOwnPropertyNames;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __moduleCache = /* @__PURE__ */ new WeakMap;
6
+ var __toCommonJS = (from) => {
7
+ var entry = __moduleCache.get(from), desc;
8
+ if (entry)
9
+ return entry;
10
+ entry = __defProp({}, "__esModule", { value: true });
11
+ if (from && typeof from === "object" || typeof from === "function")
12
+ __getOwnPropNames(from).map((key) => !__hasOwnProp.call(entry, key) && __defProp(entry, key, {
13
+ get: () => from[key],
14
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
15
+ }));
16
+ __moduleCache.set(from, entry);
17
+ return entry;
18
+ };
19
+ var __export = (target, all) => {
20
+ for (var name in all)
21
+ __defProp(target, name, {
22
+ get: all[name],
23
+ enumerable: true,
24
+ configurable: true,
25
+ set: (newValue) => all[name] = () => newValue
26
+ });
27
+ };
28
+
29
+ // src/serializer.ts
30
+ var exports_serializer = {};
31
+ __export(exports_serializer, {
32
+ default: () => serializer_default,
33
+ createFacetpackSerializer: () => createFacetpackSerializer
34
+ });
35
+ module.exports = __toCommonJS(exports_serializer);
36
+ var import_facetpack_native = require("@ecrindigital/facetpack-native");
37
+ function createFacetpackSerializer(existingSerializer, config = {}) {
38
+ return async (entryPoint, preModules, graph, options) => {
39
+ if (options.dev || config.treeShake === false) {
40
+ if (existingSerializer) {
41
+ return existingSerializer(entryPoint, preModules, graph, options);
42
+ }
43
+ return defaultSerialize(entryPoint, preModules, graph, options);
44
+ }
45
+ const analyses = new Map;
46
+ for (const [path, module2] of graph.dependencies) {
47
+ if (path.includes("node_modules")) {
48
+ continue;
49
+ }
50
+ try {
51
+ const code = module2.output[0]?.data?.code ?? "";
52
+ const analysis = import_facetpack_native.analyzeSync(path, code);
53
+ analyses.set(path, analysis);
54
+ } catch {
55
+ analyses.set(path, {
56
+ exports: [],
57
+ imports: [],
58
+ hasSideEffects: true
59
+ });
60
+ }
61
+ }
62
+ const usedExports = computeUsedExports(entryPoint, analyses, graph);
63
+ const shakenModules = new Map;
64
+ let totalRemoved = 0;
65
+ for (const [path, module2] of graph.dependencies) {
66
+ if (path.includes("node_modules")) {
67
+ const code = module2.output[0]?.data?.code ?? "";
68
+ shakenModules.set(path, { code });
69
+ continue;
70
+ }
71
+ const used = usedExports.get(path);
72
+ const analysis = analyses.get(path);
73
+ if ((!used || used.size === 0) && analysis && !analysis.hasSideEffects) {
74
+ totalRemoved++;
75
+ continue;
76
+ }
77
+ try {
78
+ const code = module2.output[0]?.data?.code ?? "";
79
+ const usedArray = used ? Array.from(used) : ["*"];
80
+ const result = import_facetpack_native.shakeSync(path, code, usedArray);
81
+ shakenModules.set(path, { code: result.code, map: result.map ?? undefined });
82
+ totalRemoved += result.removedExports.length;
83
+ } catch {
84
+ const code = module2.output[0]?.data?.code ?? "";
85
+ shakenModules.set(path, { code });
86
+ }
87
+ }
88
+ if (totalRemoved > 0) {
89
+ console.log(`[facetpack] Tree-shaking removed ${totalRemoved} unused exports`);
90
+ }
91
+ if (existingSerializer) {
92
+ const shakenGraph = createShakenGraph(graph, shakenModules);
93
+ return existingSerializer(entryPoint, preModules, shakenGraph, options);
94
+ }
95
+ return defaultSerialize(entryPoint, preModules, graph, options, shakenModules);
96
+ };
97
+ }
98
+ function computeUsedExports(entryPoint, analyses, graph) {
99
+ const used = new Map;
100
+ const visited = new Set;
101
+ function visit(modulePath, importedNames) {
102
+ let moduleUsed = used.get(modulePath);
103
+ if (!moduleUsed) {
104
+ moduleUsed = new Set;
105
+ used.set(modulePath, moduleUsed);
106
+ }
107
+ for (const name of importedNames) {
108
+ moduleUsed.add(name);
109
+ }
110
+ if (visited.has(modulePath)) {
111
+ return;
112
+ }
113
+ visited.add(modulePath);
114
+ const analysis = analyses.get(modulePath);
115
+ if (!analysis) {
116
+ return;
117
+ }
118
+ for (const imp of analysis.imports) {
119
+ const module2 = graph.dependencies.get(modulePath);
120
+ if (!module2)
121
+ continue;
122
+ const resolvedPath = module2.dependencies.get(imp.source);
123
+ if (resolvedPath) {
124
+ visit(resolvedPath, imp.specifiers);
125
+ }
126
+ }
127
+ for (const exp of analysis.exports) {
128
+ if (exp.isReexport && exp.source) {
129
+ const module2 = graph.dependencies.get(modulePath);
130
+ if (!module2)
131
+ continue;
132
+ const resolvedPath = module2.dependencies.get(exp.source);
133
+ if (resolvedPath && moduleUsed.has(exp.name)) {
134
+ visit(resolvedPath, [exp.name === "*" ? "*" : exp.name]);
135
+ }
136
+ }
137
+ }
138
+ }
139
+ visit(entryPoint, ["*"]);
140
+ return used;
141
+ }
142
+ function createShakenGraph(originalGraph, shakenModules) {
143
+ const newDependencies = new Map;
144
+ for (const [path, module2] of originalGraph.dependencies) {
145
+ const shaken = shakenModules.get(path);
146
+ if (shaken) {
147
+ newDependencies.set(path, {
148
+ ...module2,
149
+ output: [
150
+ {
151
+ data: {
152
+ code: shaken.code,
153
+ map: shaken.map
154
+ }
155
+ }
156
+ ]
157
+ });
158
+ }
159
+ }
160
+ return {
161
+ dependencies: newDependencies,
162
+ entryPoints: originalGraph.entryPoints
163
+ };
164
+ }
165
+ function defaultSerialize(entryPoint, preModules, graph, options, shakenModules) {
166
+ const modules = [];
167
+ let moduleId = 0;
168
+ const moduleIds = new Map;
169
+ for (const module2 of preModules) {
170
+ const code = module2.output[0]?.data?.code ?? "";
171
+ const id = options.createModuleId?.(module2.path) ?? moduleId++;
172
+ moduleIds.set(module2.path, id);
173
+ modules.push(wrapModule(id, code));
174
+ }
175
+ for (const [path] of graph.dependencies) {
176
+ const shaken = shakenModules?.get(path);
177
+ const module2 = graph.dependencies.get(path);
178
+ const code = shaken?.code ?? module2?.output[0]?.data?.code ?? "";
179
+ const id = options.createModuleId?.(path) ?? moduleId++;
180
+ moduleIds.set(path, id);
181
+ modules.push(wrapModule(id, code));
182
+ }
183
+ const entryId = moduleIds.get(entryPoint) ?? 0;
184
+ const runStatement = options.getRunModuleStatement?.(entryId) ?? `__r(${entryId});`;
185
+ const bundleCode = modules.join(`
186
+ `) + `
187
+ ` + runStatement;
188
+ return {
189
+ code: bundleCode,
190
+ map: '{"version":3,"sources":[],"mappings":""}'
191
+ };
192
+ }
193
+ function wrapModule(id, code) {
194
+ return `__d(function(g,r,i,a,m,e,d){${code}},${id});`;
195
+ }
196
+ var serializer_default = createFacetpackSerializer;
@@ -0,0 +1,59 @@
1
+ export interface SerializerModule {
2
+ path: string;
3
+ output: Array<{
4
+ data: {
5
+ code: string;
6
+ map?: string;
7
+ };
8
+ }>;
9
+ dependencies: Map<string, string>;
10
+ }
11
+ export interface SerializerGraph {
12
+ dependencies: Map<string, SerializerModule>;
13
+ entryPoints: Set<string>;
14
+ }
15
+ export interface SerializerOptions {
16
+ dev: boolean;
17
+ minify: boolean;
18
+ platform?: string;
19
+ projectRoot: string;
20
+ processModuleFilter?: (module: SerializerModule) => boolean;
21
+ createModuleId?: (path: string) => number;
22
+ getRunModuleStatement?: (moduleId: number) => string;
23
+ shouldAddToIgnoreList?: (module: SerializerModule) => boolean;
24
+ }
25
+ export interface SerializerParams {
26
+ entryPoint: string;
27
+ preModules: SerializerModule[];
28
+ graph: SerializerGraph;
29
+ options: SerializerOptions;
30
+ }
31
+ export type CustomSerializer = (entryPoint: string, preModules: SerializerModule[], graph: SerializerGraph, options: SerializerOptions) => string | {
32
+ code: string;
33
+ map: string;
34
+ } | Promise<string | {
35
+ code: string;
36
+ map: string;
37
+ }>;
38
+ export interface FacetpackSerializerConfig {
39
+ treeShake?: boolean;
40
+ }
41
+ /**
42
+ * Creates a Facetpack serializer with tree-shaking support.
43
+ * This serializer can be composed with existing Metro serializers.
44
+ *
45
+ * @example
46
+ * ```js
47
+ * // metro.config.js
48
+ * const { createFacetpackSerializer } = require('@ecrindigital/facetpack')
49
+ *
50
+ * module.exports = {
51
+ * serializer: {
52
+ * customSerializer: createFacetpackSerializer(null, { treeShake: true }),
53
+ * },
54
+ * }
55
+ * ```
56
+ */
57
+ export declare function createFacetpackSerializer(existingSerializer?: CustomSerializer | null, config?: FacetpackSerializerConfig): CustomSerializer;
58
+ export default createFacetpackSerializer;
59
+ //# sourceMappingURL=serializer.d.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EAAE,iBAAiB,KACvB,MAAM,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAAC,MAAM,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC,CAAA;AAE7F,MAAM,WAAW,yBAAyB;IACxC,SAAS,CAAC,EAAE,OAAO,CAAA;CACpB;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,yBAAyB,CACvC,kBAAkB,CAAC,EAAE,gBAAgB,GAAG,IAAI,EAC5C,MAAM,GAAE,yBAA8B,GACrC,gBAAgB,CA4ElB;AAkID,eAAe,yBAAyB,CAAA"}
@@ -0,0 +1,172 @@
1
+ import { createRequire } from "node:module";
2
+ var __require = /* @__PURE__ */ createRequire(import.meta.url);
3
+
4
+ // src/serializer.ts
5
+ import {
6
+ analyzeSync,
7
+ shakeSync
8
+ } from "@ecrindigital/facetpack-native";
9
+ function createFacetpackSerializer(existingSerializer, config = {}) {
10
+ return async (entryPoint, preModules, graph, options) => {
11
+ if (options.dev || config.treeShake === false) {
12
+ if (existingSerializer) {
13
+ return existingSerializer(entryPoint, preModules, graph, options);
14
+ }
15
+ return defaultSerialize(entryPoint, preModules, graph, options);
16
+ }
17
+ const analyses = new Map;
18
+ for (const [path, module] of graph.dependencies) {
19
+ if (path.includes("node_modules")) {
20
+ continue;
21
+ }
22
+ try {
23
+ const code = module.output[0]?.data?.code ?? "";
24
+ const analysis = analyzeSync(path, code);
25
+ analyses.set(path, analysis);
26
+ } catch {
27
+ analyses.set(path, {
28
+ exports: [],
29
+ imports: [],
30
+ hasSideEffects: true
31
+ });
32
+ }
33
+ }
34
+ const usedExports = computeUsedExports(entryPoint, analyses, graph);
35
+ const shakenModules = new Map;
36
+ let totalRemoved = 0;
37
+ for (const [path, module] of graph.dependencies) {
38
+ if (path.includes("node_modules")) {
39
+ const code = module.output[0]?.data?.code ?? "";
40
+ shakenModules.set(path, { code });
41
+ continue;
42
+ }
43
+ const used = usedExports.get(path);
44
+ const analysis = analyses.get(path);
45
+ if ((!used || used.size === 0) && analysis && !analysis.hasSideEffects) {
46
+ totalRemoved++;
47
+ continue;
48
+ }
49
+ try {
50
+ const code = module.output[0]?.data?.code ?? "";
51
+ const usedArray = used ? Array.from(used) : ["*"];
52
+ const result = shakeSync(path, code, usedArray);
53
+ shakenModules.set(path, { code: result.code, map: result.map ?? undefined });
54
+ totalRemoved += result.removedExports.length;
55
+ } catch {
56
+ const code = module.output[0]?.data?.code ?? "";
57
+ shakenModules.set(path, { code });
58
+ }
59
+ }
60
+ if (totalRemoved > 0) {
61
+ console.log(`[facetpack] Tree-shaking removed ${totalRemoved} unused exports`);
62
+ }
63
+ if (existingSerializer) {
64
+ const shakenGraph = createShakenGraph(graph, shakenModules);
65
+ return existingSerializer(entryPoint, preModules, shakenGraph, options);
66
+ }
67
+ return defaultSerialize(entryPoint, preModules, graph, options, shakenModules);
68
+ };
69
+ }
70
+ function computeUsedExports(entryPoint, analyses, graph) {
71
+ const used = new Map;
72
+ const visited = new Set;
73
+ function visit(modulePath, importedNames) {
74
+ let moduleUsed = used.get(modulePath);
75
+ if (!moduleUsed) {
76
+ moduleUsed = new Set;
77
+ used.set(modulePath, moduleUsed);
78
+ }
79
+ for (const name of importedNames) {
80
+ moduleUsed.add(name);
81
+ }
82
+ if (visited.has(modulePath)) {
83
+ return;
84
+ }
85
+ visited.add(modulePath);
86
+ const analysis = analyses.get(modulePath);
87
+ if (!analysis) {
88
+ return;
89
+ }
90
+ for (const imp of analysis.imports) {
91
+ const module = graph.dependencies.get(modulePath);
92
+ if (!module)
93
+ continue;
94
+ const resolvedPath = module.dependencies.get(imp.source);
95
+ if (resolvedPath) {
96
+ visit(resolvedPath, imp.specifiers);
97
+ }
98
+ }
99
+ for (const exp of analysis.exports) {
100
+ if (exp.isReexport && exp.source) {
101
+ const module = graph.dependencies.get(modulePath);
102
+ if (!module)
103
+ continue;
104
+ const resolvedPath = module.dependencies.get(exp.source);
105
+ if (resolvedPath && moduleUsed.has(exp.name)) {
106
+ visit(resolvedPath, [exp.name === "*" ? "*" : exp.name]);
107
+ }
108
+ }
109
+ }
110
+ }
111
+ visit(entryPoint, ["*"]);
112
+ return used;
113
+ }
114
+ function createShakenGraph(originalGraph, shakenModules) {
115
+ const newDependencies = new Map;
116
+ for (const [path, module] of originalGraph.dependencies) {
117
+ const shaken = shakenModules.get(path);
118
+ if (shaken) {
119
+ newDependencies.set(path, {
120
+ ...module,
121
+ output: [
122
+ {
123
+ data: {
124
+ code: shaken.code,
125
+ map: shaken.map
126
+ }
127
+ }
128
+ ]
129
+ });
130
+ }
131
+ }
132
+ return {
133
+ dependencies: newDependencies,
134
+ entryPoints: originalGraph.entryPoints
135
+ };
136
+ }
137
+ function defaultSerialize(entryPoint, preModules, graph, options, shakenModules) {
138
+ const modules = [];
139
+ let moduleId = 0;
140
+ const moduleIds = new Map;
141
+ for (const module of preModules) {
142
+ const code = module.output[0]?.data?.code ?? "";
143
+ const id = options.createModuleId?.(module.path) ?? moduleId++;
144
+ moduleIds.set(module.path, id);
145
+ modules.push(wrapModule(id, code));
146
+ }
147
+ for (const [path] of graph.dependencies) {
148
+ const shaken = shakenModules?.get(path);
149
+ const module = graph.dependencies.get(path);
150
+ const code = shaken?.code ?? module?.output[0]?.data?.code ?? "";
151
+ const id = options.createModuleId?.(path) ?? moduleId++;
152
+ moduleIds.set(path, id);
153
+ modules.push(wrapModule(id, code));
154
+ }
155
+ const entryId = moduleIds.get(entryPoint) ?? 0;
156
+ const runStatement = options.getRunModuleStatement?.(entryId) ?? `__r(${entryId});`;
157
+ const bundleCode = modules.join(`
158
+ `) + `
159
+ ` + runStatement;
160
+ return {
161
+ code: bundleCode,
162
+ map: '{"version":3,"sources":[],"mappings":""}'
163
+ };
164
+ }
165
+ function wrapModule(id, code) {
166
+ return `__d(function(g,r,i,a,m,e,d){${code}},${id});`;
167
+ }
168
+ var serializer_default = createFacetpackSerializer;
169
+ export {
170
+ serializer_default as default,
171
+ createFacetpackSerializer
172
+ };
@@ -90,7 +90,9 @@ var defaultOptions = {
90
90
  jsxPragma: "React.createElement",
91
91
  jsxPragmaFrag: "React.Fragment",
92
92
  typescript: true,
93
- sourceExts: ["ts", "tsx", "js", "jsx", "mjs", "cjs"]
93
+ sourceExts: ["ts", "tsx", "js", "jsx", "mjs", "cjs"],
94
+ minifier: true,
95
+ treeShake: true
94
96
  };
95
97
  var globalOptions = {};
96
98
  var fallbackTransformer = null;
@@ -1 +1 @@
1
- {"version":3,"file":"transformer.d.ts","sourceRoot":"","sources":["../src/transformer.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAwFjF,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,gBAAgB,GAAG,IAAI,CAErE;AAoBD,wBAAgB,SAAS,CAAC,MAAM,EAAE,eAAe,GAAG,eAAe,CA6DlE;AAED,wBAAgB,iBAAiB,CAAC,OAAO,GAAE,gBAAqB;sBAI1C,eAAe,GAAG,eAAe;EA4BtD"}
1
+ {"version":3,"file":"transformer.d.ts","sourceRoot":"","sources":["../src/transformer.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AA0FjF,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,gBAAgB,GAAG,IAAI,CAErE;AAoBD,wBAAgB,SAAS,CAAC,MAAM,EAAE,eAAe,GAAG,eAAe,CA6DlE;AAED,wBAAgB,iBAAiB,CAAC,OAAO,GAAE,gBAAqB;sBAI1C,eAAe,GAAG,eAAe;EA4BtD"}
@@ -82,7 +82,9 @@ var defaultOptions = {
82
82
  jsxPragma: "React.createElement",
83
83
  jsxPragmaFrag: "React.Fragment",
84
84
  typescript: true,
85
- sourceExts: ["ts", "tsx", "js", "jsx", "mjs", "cjs"]
85
+ sourceExts: ["ts", "tsx", "js", "jsx", "mjs", "cjs"],
86
+ minifier: true,
87
+ treeShake: true
86
88
  };
87
89
  var globalOptions = {};
88
90
  var fallbackTransformer = null;
package/dist/types.d.ts CHANGED
@@ -1,3 +1,10 @@
1
+ export interface MinifierConfig {
2
+ compress?: boolean;
3
+ mangle?: boolean;
4
+ keep_fnames?: boolean;
5
+ drop_console?: boolean;
6
+ drop_debugger?: boolean;
7
+ }
1
8
  export interface FacetpackOptions {
2
9
  jsx?: boolean;
3
10
  jsxRuntime?: 'automatic' | 'classic';
@@ -6,9 +13,13 @@ export interface FacetpackOptions {
6
13
  jsxPragmaFrag?: string;
7
14
  typescript?: boolean;
8
15
  sourceExts?: string[];
16
+ minifier?: boolean | MinifierConfig;
17
+ treeShake?: boolean;
9
18
  }
10
19
  export interface MetroTransformerConfig {
11
20
  babelTransformerPath?: string;
21
+ minifierPath?: string;
22
+ minifierConfig?: MinifierConfig;
12
23
  getTransformOptions?: (entryPoints: readonly string[], options: {
13
24
  dev: boolean;
14
25
  hot: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,gBAAgB;IAC/B,GAAG,CAAC,EAAE,OAAO,CAAA;IACb,UAAU,CAAC,EAAE,WAAW,GAAG,SAAS,CAAA;IACpC,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,UAAU,CAAC,EAAE,MAAM,EAAE,CAAA;CACtB;AAED,MAAM,WAAW,sBAAsB;IACrC,oBAAoB,CAAC,EAAE,MAAM,CAAA;IAC7B,mBAAmB,CAAC,EAAE,CACpB,WAAW,EAAE,SAAS,MAAM,EAAE,EAC9B,OAAO,EAAE;QAAE,GAAG,EAAE,OAAO,CAAC;QAAC,GAAG,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AE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAChD,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CACvB;AAED,MAAM,WAAW,eAAe;IAC9B,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;IACZ,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CACpB"}
@@ -1 +1 @@
1
- {"version":3,"file":"withFacetpack.d.ts","sourceRoot":"","sources":["../src/withFacetpack.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAW5D,wBAAgB,aAAa,CAC3B,MAAM,EAAE,WAAW,EACnB,OAAO,GAAE,gBAAqB,GAC7B,WAAW,CAwEb;AAMD,wBAAgB,gBAAgB,IAAI,gBAAgB,CASnD"}
1
+ {"version":3,"file":"withFacetpack.d.ts","sourceRoot":"","sources":["../src/withFacetpack.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,gBAAgB,EAAkB,MAAM,SAAS,CAAA;AAY5E,wBAAgB,aAAa,CAC3B,MAAM,EAAE,WAAW,EACnB,OAAO,GAAE,gBAAqB,GAC7B,WAAW,CA4Fb;AAMD,wBAAgB,gBAAgB,IAAI,gBAAgB,CASnD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ecrindigital/facetpack",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "High-performance Metro transformer powered by OXC",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -15,6 +15,16 @@
15
15
  "types": "./dist/transformer.d.ts",
16
16
  "import": "./dist/transformer.js",
17
17
  "require": "./dist/transformer.cjs"
18
+ },
19
+ "./minifier": {
20
+ "types": "./dist/minifier.d.ts",
21
+ "import": "./dist/minifier.js",
22
+ "require": "./dist/minifier.cjs"
23
+ },
24
+ "./serializer": {
25
+ "types": "./dist/serializer.d.ts",
26
+ "import": "./dist/serializer.js",
27
+ "require": "./dist/serializer.cjs"
18
28
  }
19
29
  },
20
30
  "files": [
@@ -60,8 +70,8 @@
60
70
  "typescript": "^5.7.0"
61
71
  },
62
72
  "scripts": {
63
- "build": "bun build ./src/index.ts ./src/transformer.ts --outdir ./dist --target node --format esm --external @ecrindigital/facetpack-native --external @babel/parser && bun run build:cjs && bun run build:types",
64
- "build:cjs": "bun build ./src/index.ts --outfile ./dist/index.cjs --target node --format cjs --external @ecrindigital/facetpack-native --external @babel/parser && bun build ./src/transformer.ts --outfile ./dist/transformer.cjs --target node --format cjs --external @ecrindigital/facetpack-native --external @babel/parser",
73
+ "build": "bun build ./src/index.ts ./src/transformer.ts ./src/minifier.ts ./src/serializer.ts --outdir ./dist --target node --format esm --external @ecrindigital/facetpack-native --external @babel/parser && bun run build:cjs && bun run build:types",
74
+ "build:cjs": "bun build ./src/index.ts --outfile ./dist/index.cjs --target node --format cjs --external @ecrindigital/facetpack-native --external @babel/parser && bun build ./src/transformer.ts --outfile ./dist/transformer.cjs --target node --format cjs --external @ecrindigital/facetpack-native --external @babel/parser && bun build ./src/minifier.ts --outfile ./dist/minifier.cjs --target node --format cjs --external @ecrindigital/facetpack-native --external @babel/parser && bun build ./src/serializer.ts --outfile ./dist/serializer.cjs --target node --format cjs --external @ecrindigital/facetpack-native --external @babel/parser",
65
75
  "build:types": "bunx tsc",
66
76
  "dev": "bun build ./src/index.ts --outdir ./dist --target node --watch",
67
77
  "typecheck": "tsc --noEmit",