@ionify/ionify 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.
- package/dist/cache-Y4NMRSZO.js +13 -0
- package/dist/cas-FEOXFD7R.js +7 -0
- package/dist/chunk-GOZUBOYH.js +225 -0
- package/dist/chunk-X5UIMJDA.js +11 -0
- package/dist/cli/index.cjs +3567 -183
- package/dist/cli/index.js +3219 -133
- package/package.json +1 -1
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/core/cache.ts
|
|
4
|
+
import fs2 from "fs";
|
|
5
|
+
import path2 from "path";
|
|
6
|
+
import crypto from "crypto";
|
|
7
|
+
|
|
8
|
+
// src/native/index.ts
|
|
9
|
+
import fs from "fs";
|
|
10
|
+
import path from "path";
|
|
11
|
+
import { createRequire } from "module";
|
|
12
|
+
|
|
13
|
+
// src/core/version.ts
|
|
14
|
+
import { createHash } from "crypto";
|
|
15
|
+
function normalizeTreeshake(treeshake) {
|
|
16
|
+
if (treeshake === false || treeshake === void 0 || treeshake === null) {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
if (treeshake === true) {
|
|
20
|
+
return {
|
|
21
|
+
mode: "safe",
|
|
22
|
+
include: [],
|
|
23
|
+
exclude: []
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
if (typeof treeshake === "string") {
|
|
27
|
+
return {
|
|
28
|
+
mode: treeshake === "aggressive" ? "aggressive" : "safe",
|
|
29
|
+
include: [],
|
|
30
|
+
exclude: []
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
mode: treeshake.mode === "aggressive" ? "aggressive" : "safe",
|
|
35
|
+
include: Array.isArray(treeshake.include) ? [...treeshake.include].sort() : [],
|
|
36
|
+
exclude: Array.isArray(treeshake.exclude) ? [...treeshake.exclude].sort() : []
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function normalizeScopeHoist(scopeHoist) {
|
|
40
|
+
if (scopeHoist === false || scopeHoist === void 0 || scopeHoist === null) {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
if (scopeHoist === true) {
|
|
44
|
+
return {
|
|
45
|
+
inlineFunctions: true,
|
|
46
|
+
constantFolding: true,
|
|
47
|
+
combineVariables: true
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
inlineFunctions: scopeHoist.inlineFunctions === true,
|
|
52
|
+
constantFolding: scopeHoist.constantFolding === true,
|
|
53
|
+
combineVariables: scopeHoist.combineVariables === true
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
function computeCanonicalVersionInputs(config) {
|
|
57
|
+
const parserMode = config.parserMode || "hybrid";
|
|
58
|
+
const minifier = config.minifier || "auto";
|
|
59
|
+
const treeshake = normalizeTreeshake(config.treeshake);
|
|
60
|
+
const scopeHoist = normalizeScopeHoist(config.scopeHoist);
|
|
61
|
+
const plugins = Array.isArray(config.plugins) ? config.plugins.map((p) => typeof p === "string" ? p : p.name).filter((name) => typeof name === "string").sort() : [];
|
|
62
|
+
let entry = null;
|
|
63
|
+
if (config.entry) {
|
|
64
|
+
if (typeof config.entry === "string") {
|
|
65
|
+
entry = [config.entry];
|
|
66
|
+
} else if (Array.isArray(config.entry)) {
|
|
67
|
+
entry = [...config.entry].sort();
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
const cssOptions = config.cssOptions && Object.keys(config.cssOptions).length > 0 ? config.cssOptions : null;
|
|
71
|
+
const assetOptions = config.assetOptions && Object.keys(config.assetOptions).length > 0 ? config.assetOptions : null;
|
|
72
|
+
return {
|
|
73
|
+
parserMode,
|
|
74
|
+
minifier,
|
|
75
|
+
treeshake,
|
|
76
|
+
scopeHoist,
|
|
77
|
+
plugins,
|
|
78
|
+
entry,
|
|
79
|
+
cssOptions,
|
|
80
|
+
assetOptions
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
function computeVersionHash(inputs) {
|
|
84
|
+
const json = JSON.stringify(inputs, Object.keys(inputs).sort());
|
|
85
|
+
const hash = createHash("sha256").update(json).digest("hex");
|
|
86
|
+
return hash.slice(0, 16);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// src/native/index.ts
|
|
90
|
+
function resolveCandidates() {
|
|
91
|
+
const cwd = process.cwd();
|
|
92
|
+
const releaseDir = path.resolve(cwd, "target", "release");
|
|
93
|
+
const debugDir = path.resolve(cwd, "target", "debug");
|
|
94
|
+
const nativeDir = path.resolve(cwd, "native");
|
|
95
|
+
const moduleDir = path.dirname(new URL(import.meta.url).pathname);
|
|
96
|
+
const packageNativeDir = path.resolve(moduleDir, "..", "native");
|
|
97
|
+
const packageDistDir = path.resolve(moduleDir, "..");
|
|
98
|
+
const platformFile = process.platform === "win32" ? "ionify_core.dll" : process.platform === "darwin" ? "libionify_core.dylib" : "libionify_core.so";
|
|
99
|
+
const candidates = [
|
|
100
|
+
// Installed package locations (checked first)
|
|
101
|
+
path.join(packageDistDir, "ionify_core.node"),
|
|
102
|
+
path.join(packageNativeDir, "ionify_core.node"),
|
|
103
|
+
// Development locations
|
|
104
|
+
path.join(nativeDir, "ionify_core.node"),
|
|
105
|
+
path.join(releaseDir, "ionify_core.node"),
|
|
106
|
+
path.join(releaseDir, platformFile),
|
|
107
|
+
path.join(debugDir, "ionify_core.node"),
|
|
108
|
+
path.join(debugDir, platformFile)
|
|
109
|
+
];
|
|
110
|
+
return candidates.filter((candidate) => {
|
|
111
|
+
try {
|
|
112
|
+
return fs.existsSync(candidate) && fs.statSync(candidate).isFile();
|
|
113
|
+
} catch {
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
var nativeBinding = null;
|
|
119
|
+
(() => {
|
|
120
|
+
const require2 = createRequire(import.meta.url);
|
|
121
|
+
for (const candidate of resolveCandidates()) {
|
|
122
|
+
try {
|
|
123
|
+
const mod = require2(candidate);
|
|
124
|
+
if (mod) {
|
|
125
|
+
nativeBinding = mod;
|
|
126
|
+
break;
|
|
127
|
+
}
|
|
128
|
+
} catch {
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
})();
|
|
132
|
+
var native = nativeBinding;
|
|
133
|
+
function tryNativeTransform(mode, code, options) {
|
|
134
|
+
if (!nativeBinding) return null;
|
|
135
|
+
const wantsOxc = mode === "oxc" || mode === "hybrid";
|
|
136
|
+
const wantsSwc = mode === "swc" || mode === "hybrid";
|
|
137
|
+
if (wantsOxc && nativeBinding.parseAndTransformOxc) {
|
|
138
|
+
try {
|
|
139
|
+
return nativeBinding.parseAndTransformOxc(code, options);
|
|
140
|
+
} catch (err) {
|
|
141
|
+
if (mode === "oxc") throw err;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
if (wantsSwc && nativeBinding.parseAndTransformSwc) {
|
|
145
|
+
try {
|
|
146
|
+
return nativeBinding.parseAndTransformSwc(code, options);
|
|
147
|
+
} catch (err) {
|
|
148
|
+
if (mode === "swc") throw err;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return null;
|
|
152
|
+
}
|
|
153
|
+
function ensureNativeGraph(graphPath, version) {
|
|
154
|
+
if (!nativeBinding?.graphInit) return;
|
|
155
|
+
try {
|
|
156
|
+
nativeBinding.graphInit(graphPath, version);
|
|
157
|
+
} catch (err) {
|
|
158
|
+
console.error(`[Native] Failed to initialize graph: ${err}`);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
function computeGraphVersion(inputs) {
|
|
162
|
+
const canonical = computeCanonicalVersionInputs(inputs);
|
|
163
|
+
return computeVersionHash(canonical);
|
|
164
|
+
}
|
|
165
|
+
function tryBundleNodeModule(filePath, code) {
|
|
166
|
+
if (!nativeBinding?.plannerPlanBuild || !nativeBinding?.buildChunks) {
|
|
167
|
+
return null;
|
|
168
|
+
}
|
|
169
|
+
try {
|
|
170
|
+
const plan = nativeBinding.plannerPlanBuild([filePath]);
|
|
171
|
+
if (!plan || !plan.chunks || plan.chunks.length === 0) {
|
|
172
|
+
return null;
|
|
173
|
+
}
|
|
174
|
+
const artifacts = nativeBinding.buildChunks(plan);
|
|
175
|
+
if (artifacts && artifacts.length > 0 && artifacts[0].code) {
|
|
176
|
+
return artifacts[0].code;
|
|
177
|
+
}
|
|
178
|
+
} catch (error) {
|
|
179
|
+
console.warn(`[Ionify] Native bundler failed for ${filePath}:`, error);
|
|
180
|
+
}
|
|
181
|
+
return null;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// src/core/cache.ts
|
|
185
|
+
var CACHE_DIR = path2.join(process.cwd(), ".ionify", "cache");
|
|
186
|
+
function ensureCacheDir() {
|
|
187
|
+
if (!fs2.existsSync(CACHE_DIR)) {
|
|
188
|
+
fs2.mkdirSync(CACHE_DIR, { recursive: true });
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
function getCacheKey(content) {
|
|
192
|
+
if (native?.cacheHash) {
|
|
193
|
+
try {
|
|
194
|
+
return native.cacheHash(Buffer.from(content));
|
|
195
|
+
} catch {
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
return crypto.createHash("sha256").update(content).digest("hex");
|
|
199
|
+
}
|
|
200
|
+
function writeCache(hash, data) {
|
|
201
|
+
ensureCacheDir();
|
|
202
|
+
const target = path2.join(CACHE_DIR, hash);
|
|
203
|
+
fs2.writeFileSync(target, data);
|
|
204
|
+
}
|
|
205
|
+
function readCache(hash) {
|
|
206
|
+
const target = path2.join(CACHE_DIR, hash);
|
|
207
|
+
return fs2.existsSync(target) ? fs2.readFileSync(target) : null;
|
|
208
|
+
}
|
|
209
|
+
function clearCache() {
|
|
210
|
+
if (fs2.existsSync(CACHE_DIR)) {
|
|
211
|
+
fs2.rmSync(CACHE_DIR, { recursive: true, force: true });
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
export {
|
|
216
|
+
native,
|
|
217
|
+
tryNativeTransform,
|
|
218
|
+
ensureNativeGraph,
|
|
219
|
+
computeGraphVersion,
|
|
220
|
+
tryBundleNodeModule,
|
|
221
|
+
getCacheKey,
|
|
222
|
+
writeCache,
|
|
223
|
+
readCache,
|
|
224
|
+
clearCache
|
|
225
|
+
};
|