@hirarijs/loader 1.0.8 → 1.0.10
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/chunk-2YMWZ4IT.js +289 -0
- package/dist/chunk-B6QICL5V.js +293 -0
- package/dist/chunk-DB7XPVAR.js +293 -0
- package/dist/chunk-J2O76MZJ.js +15 -0
- package/dist/chunk-J3YUVEEK.js +15 -0
- package/dist/chunk-JPHIWQ7S.js +15 -0
- package/dist/chunk-O7SYNOVB.js +296 -0
- package/dist/chunk-XTXLI7WO.js +15 -0
- package/dist/index.cjs +25 -20
- package/dist/index.d.cts +7 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +2 -2
- package/dist/loader.cjs +28 -27
- package/dist/loader.js +1 -1
- package/dist/register-auto.cjs +25 -20
- package/dist/register-auto.js +2 -2
- package/dist/register.cjs +25 -20
- package/dist/register.js +2 -2
- package/package.json +2 -1
package/dist/index.cjs
CHANGED
|
@@ -44,7 +44,12 @@ var import_fs = __toESM(require("fs"), 1);
|
|
|
44
44
|
var import_path = __toESM(require("path"), 1);
|
|
45
45
|
var DEFAULT_CONFIG = {
|
|
46
46
|
format: "cjs",
|
|
47
|
-
plugins: [
|
|
47
|
+
plugins: [
|
|
48
|
+
"@hirarijs/loader-ts",
|
|
49
|
+
"@hirarijs/loader-tsx",
|
|
50
|
+
"@hirarijs/loader-vue",
|
|
51
|
+
"@hirarijs/loader-cjs-interop"
|
|
52
|
+
]
|
|
48
53
|
};
|
|
49
54
|
function loadHirariConfig(cwd = process.cwd()) {
|
|
50
55
|
const configPath = import_path.default.join(cwd, "hirari.json");
|
|
@@ -168,30 +173,30 @@ function createRuntime(cwd = process.cwd()) {
|
|
|
168
173
|
format: getFormat(loaderConfig)
|
|
169
174
|
};
|
|
170
175
|
}
|
|
171
|
-
function pickPlugin(filename, plugins) {
|
|
172
|
-
return plugins.find(({ plugin }) => plugin.match(filename));
|
|
173
|
-
}
|
|
174
176
|
function applyPlugin(code, filename, runtime) {
|
|
175
|
-
const match
|
|
176
|
-
|
|
177
|
+
for (const match of runtime.resolvedPlugins) {
|
|
178
|
+
if (!match.plugin.match(filename)) continue;
|
|
179
|
+
const ctx = {
|
|
180
|
+
format: runtime.format,
|
|
181
|
+
loaderConfig: runtime.loaderConfig,
|
|
182
|
+
pluginOptions: match.options
|
|
183
|
+
};
|
|
184
|
+
const result = match.plugin.transform(code, filename, ctx);
|
|
177
185
|
if (runtime.loaderConfig.debug) {
|
|
178
|
-
console.log(`[hirari-loader]
|
|
186
|
+
console.log(`[hirari-loader][${match.plugin.name}] compiled ${filename}`);
|
|
187
|
+
}
|
|
188
|
+
if (result.continue) {
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
191
|
+
if (result.map) {
|
|
192
|
+
map[filename] = result.map;
|
|
179
193
|
}
|
|
180
|
-
return
|
|
194
|
+
return result;
|
|
181
195
|
}
|
|
182
|
-
const ctx = {
|
|
183
|
-
format: runtime.format,
|
|
184
|
-
loaderConfig: runtime.loaderConfig,
|
|
185
|
-
pluginOptions: match.options
|
|
186
|
-
};
|
|
187
|
-
const result = match.plugin.transform(code, filename, ctx);
|
|
188
196
|
if (runtime.loaderConfig.debug) {
|
|
189
|
-
console.log(`[hirari-loader]
|
|
190
|
-
}
|
|
191
|
-
if (result.map) {
|
|
192
|
-
map[filename] = result.map;
|
|
197
|
+
console.log(`[hirari-loader] no plugin matched ${filename}`);
|
|
193
198
|
}
|
|
194
|
-
return
|
|
199
|
+
return { code };
|
|
195
200
|
}
|
|
196
201
|
function collectExtensions(plugins) {
|
|
197
202
|
const set = /* @__PURE__ */ new Set();
|
|
@@ -212,7 +217,7 @@ function registerRequireHooks(runtime) {
|
|
|
212
217
|
};
|
|
213
218
|
const revert = (0, import_pirates.addHook)(compile, {
|
|
214
219
|
exts: extensions,
|
|
215
|
-
ignoreNodeModules:
|
|
220
|
+
ignoreNodeModules: false
|
|
216
221
|
});
|
|
217
222
|
const extensionsObj = import_module2.default.Module._extensions;
|
|
218
223
|
const jsHandler = extensionsObj[".js"];
|
package/dist/index.d.cts
CHANGED
|
@@ -10,6 +10,10 @@ interface TransformResult {
|
|
|
10
10
|
code: string;
|
|
11
11
|
map?: string;
|
|
12
12
|
format?: ModuleFormat;
|
|
13
|
+
/**
|
|
14
|
+
* When true, loader will continue to next plugin instead of short-circuiting.
|
|
15
|
+
*/
|
|
16
|
+
continue?: boolean;
|
|
13
17
|
}
|
|
14
18
|
interface LoaderPlugin {
|
|
15
19
|
name: string;
|
|
@@ -31,6 +35,9 @@ interface LoaderConfig {
|
|
|
31
35
|
plugins?: string[];
|
|
32
36
|
pluginOptions?: Record<string, Record<string, unknown>>;
|
|
33
37
|
autoInstall?: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* @deprecated 全局 ignore 已取消,请使用各插件的 ignoreNodeModules/allowNodeModules 配置。
|
|
40
|
+
*/
|
|
34
41
|
hookIgnoreNodeModules?: boolean;
|
|
35
42
|
debug?: boolean;
|
|
36
43
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -10,6 +10,10 @@ interface TransformResult {
|
|
|
10
10
|
code: string;
|
|
11
11
|
map?: string;
|
|
12
12
|
format?: ModuleFormat;
|
|
13
|
+
/**
|
|
14
|
+
* When true, loader will continue to next plugin instead of short-circuiting.
|
|
15
|
+
*/
|
|
16
|
+
continue?: boolean;
|
|
13
17
|
}
|
|
14
18
|
interface LoaderPlugin {
|
|
15
19
|
name: string;
|
|
@@ -31,6 +35,9 @@ interface LoaderConfig {
|
|
|
31
35
|
plugins?: string[];
|
|
32
36
|
pluginOptions?: Record<string, Record<string, unknown>>;
|
|
33
37
|
autoInstall?: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* @deprecated 全局 ignore 已取消,请使用各插件的 ignoreNodeModules/allowNodeModules 配置。
|
|
40
|
+
*/
|
|
34
41
|
hookIgnoreNodeModules?: boolean;
|
|
35
42
|
debug?: boolean;
|
|
36
43
|
}
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
register
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-JPHIWQ7S.js";
|
|
4
4
|
import {
|
|
5
5
|
IMPORT_META_URL_VARIABLE,
|
|
6
6
|
createRuntime,
|
|
7
7
|
loadHirariConfig,
|
|
8
8
|
resolvePlugins
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-2YMWZ4IT.js";
|
|
10
10
|
export {
|
|
11
11
|
IMPORT_META_URL_VARIABLE,
|
|
12
12
|
createRuntime,
|
package/dist/loader.cjs
CHANGED
|
@@ -47,7 +47,12 @@ var import_fs = __toESM(require("fs"), 1);
|
|
|
47
47
|
var import_path = __toESM(require("path"), 1);
|
|
48
48
|
var DEFAULT_CONFIG = {
|
|
49
49
|
format: "cjs",
|
|
50
|
-
plugins: [
|
|
50
|
+
plugins: [
|
|
51
|
+
"@hirarijs/loader-ts",
|
|
52
|
+
"@hirarijs/loader-tsx",
|
|
53
|
+
"@hirarijs/loader-vue",
|
|
54
|
+
"@hirarijs/loader-cjs-interop"
|
|
55
|
+
]
|
|
51
56
|
};
|
|
52
57
|
function loadHirariConfig(cwd = process.cwd()) {
|
|
53
58
|
const configPath = import_path.default.join(cwd, "hirari.json");
|
|
@@ -174,41 +179,40 @@ function createRuntime(cwd = process.cwd()) {
|
|
|
174
179
|
format: getFormat(loaderConfig)
|
|
175
180
|
};
|
|
176
181
|
}
|
|
177
|
-
function pickPlugin(filename, plugins) {
|
|
178
|
-
return plugins.find(({ plugin }) => plugin.match(filename));
|
|
179
|
-
}
|
|
180
182
|
function applyPlugin(code, filename, runtime2) {
|
|
181
|
-
const match
|
|
182
|
-
|
|
183
|
+
for (const match of runtime2.resolvedPlugins) {
|
|
184
|
+
if (!match.plugin.match(filename)) continue;
|
|
185
|
+
const ctx = {
|
|
186
|
+
format: runtime2.format,
|
|
187
|
+
loaderConfig: runtime2.loaderConfig,
|
|
188
|
+
pluginOptions: match.options
|
|
189
|
+
};
|
|
190
|
+
const result = match.plugin.transform(code, filename, ctx);
|
|
183
191
|
if (runtime2.loaderConfig.debug) {
|
|
184
|
-
console.log(`[hirari-loader]
|
|
192
|
+
console.log(`[hirari-loader][${match.plugin.name}] compiled ${filename}`);
|
|
193
|
+
}
|
|
194
|
+
if (result.continue) {
|
|
195
|
+
continue;
|
|
185
196
|
}
|
|
186
|
-
|
|
197
|
+
if (result.map) {
|
|
198
|
+
map[filename] = result.map;
|
|
199
|
+
}
|
|
200
|
+
return result;
|
|
187
201
|
}
|
|
188
|
-
const ctx = {
|
|
189
|
-
format: runtime2.format,
|
|
190
|
-
loaderConfig: runtime2.loaderConfig,
|
|
191
|
-
pluginOptions: match.options
|
|
192
|
-
};
|
|
193
|
-
const result = match.plugin.transform(code, filename, ctx);
|
|
194
202
|
if (runtime2.loaderConfig.debug) {
|
|
195
|
-
console.log(`[hirari-loader]
|
|
203
|
+
console.log(`[hirari-loader] no plugin matched ${filename}`);
|
|
196
204
|
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
return
|
|
205
|
+
return { code };
|
|
206
|
+
}
|
|
207
|
+
function pickPlugin(filename, runtime2) {
|
|
208
|
+
return runtime2.resolvedPlugins.find(({ plugin }) => plugin.match(filename));
|
|
201
209
|
}
|
|
202
210
|
async function loaderResolve(specifier, context, next, runtime2) {
|
|
203
|
-
const ignoreNodeModules = runtime2.loaderConfig.hookIgnoreNodeModules ?? true;
|
|
204
211
|
const parentUrl = context && context.parentURL;
|
|
205
212
|
const baseDir = parentUrl && typeof parentUrl === "string" && parentUrl.startsWith("file:") ? import_path3.default.dirname((0, import_url.fileURLToPath)(parentUrl)) : process.cwd();
|
|
206
213
|
const tryResolve = (basePath, note) => {
|
|
207
214
|
for (const ext2 of EXTENSION_CANDIDATES) {
|
|
208
215
|
const candidate = basePath + ext2;
|
|
209
|
-
if (ignoreNodeModules && candidate.includes("node_modules")) {
|
|
210
|
-
continue;
|
|
211
|
-
}
|
|
212
216
|
if (import_fs3.default.existsSync(candidate) && import_fs3.default.statSync(candidate).isFile()) {
|
|
213
217
|
const url = (0, import_url.pathToFileURL)(candidate).href;
|
|
214
218
|
if (runtime2.loaderConfig.debug) {
|
|
@@ -217,9 +221,6 @@ async function loaderResolve(specifier, context, next, runtime2) {
|
|
|
217
221
|
return { url, shortCircuit: true };
|
|
218
222
|
}
|
|
219
223
|
const indexCandidate = import_path3.default.join(basePath, "index" + ext2);
|
|
220
|
-
if (ignoreNodeModules && indexCandidate.includes("node_modules")) {
|
|
221
|
-
continue;
|
|
222
|
-
}
|
|
223
224
|
if (import_fs3.default.existsSync(indexCandidate) && import_fs3.default.statSync(indexCandidate).isFile()) {
|
|
224
225
|
const url = (0, import_url.pathToFileURL)(indexCandidate).href;
|
|
225
226
|
if (runtime2.loaderConfig.debug) {
|
|
@@ -249,7 +250,7 @@ async function loaderLoad(url, context, next, runtime2) {
|
|
|
249
250
|
const { format: expectedFormat } = runtime2;
|
|
250
251
|
if (url.startsWith("file://")) {
|
|
251
252
|
const filename = (0, import_url.fileURLToPath)(url);
|
|
252
|
-
const match = pickPlugin(filename, runtime2
|
|
253
|
+
const match = pickPlugin(filename, runtime2);
|
|
253
254
|
if (runtime2.loaderConfig.debug) {
|
|
254
255
|
console.log(`[hirari-loader] load hook url=${url} match=${!!match}`);
|
|
255
256
|
}
|
package/dist/loader.js
CHANGED
package/dist/register-auto.cjs
CHANGED
|
@@ -36,7 +36,12 @@ var import_fs = __toESM(require("fs"), 1);
|
|
|
36
36
|
var import_path = __toESM(require("path"), 1);
|
|
37
37
|
var DEFAULT_CONFIG = {
|
|
38
38
|
format: "cjs",
|
|
39
|
-
plugins: [
|
|
39
|
+
plugins: [
|
|
40
|
+
"@hirarijs/loader-ts",
|
|
41
|
+
"@hirarijs/loader-tsx",
|
|
42
|
+
"@hirarijs/loader-vue",
|
|
43
|
+
"@hirarijs/loader-cjs-interop"
|
|
44
|
+
]
|
|
40
45
|
};
|
|
41
46
|
function loadHirariConfig(cwd = process.cwd()) {
|
|
42
47
|
const configPath = import_path.default.join(cwd, "hirari.json");
|
|
@@ -151,30 +156,30 @@ function createRuntime(cwd = process.cwd()) {
|
|
|
151
156
|
format: getFormat(loaderConfig)
|
|
152
157
|
};
|
|
153
158
|
}
|
|
154
|
-
function pickPlugin(filename, plugins) {
|
|
155
|
-
return plugins.find(({ plugin }) => plugin.match(filename));
|
|
156
|
-
}
|
|
157
159
|
function applyPlugin(code, filename, runtime) {
|
|
158
|
-
const match
|
|
159
|
-
|
|
160
|
+
for (const match of runtime.resolvedPlugins) {
|
|
161
|
+
if (!match.plugin.match(filename)) continue;
|
|
162
|
+
const ctx = {
|
|
163
|
+
format: runtime.format,
|
|
164
|
+
loaderConfig: runtime.loaderConfig,
|
|
165
|
+
pluginOptions: match.options
|
|
166
|
+
};
|
|
167
|
+
const result = match.plugin.transform(code, filename, ctx);
|
|
160
168
|
if (runtime.loaderConfig.debug) {
|
|
161
|
-
console.log(`[hirari-loader]
|
|
169
|
+
console.log(`[hirari-loader][${match.plugin.name}] compiled ${filename}`);
|
|
170
|
+
}
|
|
171
|
+
if (result.continue) {
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
if (result.map) {
|
|
175
|
+
map[filename] = result.map;
|
|
162
176
|
}
|
|
163
|
-
return
|
|
177
|
+
return result;
|
|
164
178
|
}
|
|
165
|
-
const ctx = {
|
|
166
|
-
format: runtime.format,
|
|
167
|
-
loaderConfig: runtime.loaderConfig,
|
|
168
|
-
pluginOptions: match.options
|
|
169
|
-
};
|
|
170
|
-
const result = match.plugin.transform(code, filename, ctx);
|
|
171
179
|
if (runtime.loaderConfig.debug) {
|
|
172
|
-
console.log(`[hirari-loader]
|
|
173
|
-
}
|
|
174
|
-
if (result.map) {
|
|
175
|
-
map[filename] = result.map;
|
|
180
|
+
console.log(`[hirari-loader] no plugin matched ${filename}`);
|
|
176
181
|
}
|
|
177
|
-
return
|
|
182
|
+
return { code };
|
|
178
183
|
}
|
|
179
184
|
function collectExtensions(plugins) {
|
|
180
185
|
const set = /* @__PURE__ */ new Set();
|
|
@@ -195,7 +200,7 @@ function registerRequireHooks(runtime) {
|
|
|
195
200
|
};
|
|
196
201
|
const revert = (0, import_pirates.addHook)(compile, {
|
|
197
202
|
exts: extensions,
|
|
198
|
-
ignoreNodeModules:
|
|
203
|
+
ignoreNodeModules: false
|
|
199
204
|
});
|
|
200
205
|
const extensionsObj = import_module2.default.Module._extensions;
|
|
201
206
|
const jsHandler = extensionsObj[".js"];
|
package/dist/register-auto.js
CHANGED
package/dist/register.cjs
CHANGED
|
@@ -48,7 +48,12 @@ var import_fs = __toESM(require("fs"), 1);
|
|
|
48
48
|
var import_path = __toESM(require("path"), 1);
|
|
49
49
|
var DEFAULT_CONFIG = {
|
|
50
50
|
format: "cjs",
|
|
51
|
-
plugins: [
|
|
51
|
+
plugins: [
|
|
52
|
+
"@hirarijs/loader-ts",
|
|
53
|
+
"@hirarijs/loader-tsx",
|
|
54
|
+
"@hirarijs/loader-vue",
|
|
55
|
+
"@hirarijs/loader-cjs-interop"
|
|
56
|
+
]
|
|
52
57
|
};
|
|
53
58
|
function loadHirariConfig(cwd = process.cwd()) {
|
|
54
59
|
const configPath = import_path.default.join(cwd, "hirari.json");
|
|
@@ -163,30 +168,30 @@ function createRuntime(cwd = process.cwd()) {
|
|
|
163
168
|
format: getFormat(loaderConfig)
|
|
164
169
|
};
|
|
165
170
|
}
|
|
166
|
-
function pickPlugin(filename, plugins) {
|
|
167
|
-
return plugins.find(({ plugin }) => plugin.match(filename));
|
|
168
|
-
}
|
|
169
171
|
function applyPlugin(code, filename, runtime) {
|
|
170
|
-
const match
|
|
171
|
-
|
|
172
|
+
for (const match of runtime.resolvedPlugins) {
|
|
173
|
+
if (!match.plugin.match(filename)) continue;
|
|
174
|
+
const ctx = {
|
|
175
|
+
format: runtime.format,
|
|
176
|
+
loaderConfig: runtime.loaderConfig,
|
|
177
|
+
pluginOptions: match.options
|
|
178
|
+
};
|
|
179
|
+
const result = match.plugin.transform(code, filename, ctx);
|
|
172
180
|
if (runtime.loaderConfig.debug) {
|
|
173
|
-
console.log(`[hirari-loader]
|
|
181
|
+
console.log(`[hirari-loader][${match.plugin.name}] compiled ${filename}`);
|
|
182
|
+
}
|
|
183
|
+
if (result.continue) {
|
|
184
|
+
continue;
|
|
185
|
+
}
|
|
186
|
+
if (result.map) {
|
|
187
|
+
map[filename] = result.map;
|
|
174
188
|
}
|
|
175
|
-
return
|
|
189
|
+
return result;
|
|
176
190
|
}
|
|
177
|
-
const ctx = {
|
|
178
|
-
format: runtime.format,
|
|
179
|
-
loaderConfig: runtime.loaderConfig,
|
|
180
|
-
pluginOptions: match.options
|
|
181
|
-
};
|
|
182
|
-
const result = match.plugin.transform(code, filename, ctx);
|
|
183
191
|
if (runtime.loaderConfig.debug) {
|
|
184
|
-
console.log(`[hirari-loader]
|
|
185
|
-
}
|
|
186
|
-
if (result.map) {
|
|
187
|
-
map[filename] = result.map;
|
|
192
|
+
console.log(`[hirari-loader] no plugin matched ${filename}`);
|
|
188
193
|
}
|
|
189
|
-
return
|
|
194
|
+
return { code };
|
|
190
195
|
}
|
|
191
196
|
function collectExtensions(plugins) {
|
|
192
197
|
const set = /* @__PURE__ */ new Set();
|
|
@@ -207,7 +212,7 @@ function registerRequireHooks(runtime) {
|
|
|
207
212
|
};
|
|
208
213
|
const revert = (0, import_pirates.addHook)(compile, {
|
|
209
214
|
exts: extensions,
|
|
210
|
-
ignoreNodeModules:
|
|
215
|
+
ignoreNodeModules: false
|
|
211
216
|
});
|
|
212
217
|
const extensionsObj = import_module2.default.Module._extensions;
|
|
213
218
|
const jsHandler = extensionsObj[".js"];
|
package/dist/register.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hirarijs/loader",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.10",
|
|
4
4
|
"description": "Runtime loader for HirariJS that wires loader plugins and config",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
"source-map-support": "^0.5.21"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
|
+
"@hirarijs/loader-cjs-interop": "*",
|
|
36
37
|
"@hirarijs/loader-ts": "*",
|
|
37
38
|
"@hirarijs/loader-tsx": "*",
|
|
38
39
|
"@hirarijs/loader-vue": "*"
|