unplugin
Advanced tools
Comparing version 1.8.2 to 1.8.3
@@ -23,3 +23,3 @@ import * as _rspack_core_dist_config_zod from '@rspack/core/dist/config/zod'; | ||
interface OnTransformArgs { | ||
contents: string; | ||
getContents: () => Promise<string>; | ||
path: string; | ||
@@ -26,0 +26,0 @@ namespace: string; |
@@ -1021,3 +1021,3 @@ "use strict"; | ||
onTransform(_options, callback) { | ||
loader.options = loader.options || _options; | ||
loader.options || (loader.options = _options); | ||
loader.onTransformCb = callback; | ||
@@ -1032,3 +1032,3 @@ } | ||
function checkFilter(options) { | ||
return loaders.length === 1 || !options?.filter || options.filter.test(args.path); | ||
return loaders.length === 1 || !(options == null ? void 0 : options.filter) || options.filter.test(args.path); | ||
} | ||
@@ -1041,5 +1041,6 @@ let result; | ||
result = await onLoadCb(args); | ||
if (result && result.contents) | ||
if (result == null ? void 0 : result.contents) | ||
break; | ||
} | ||
let fsContentsCache; | ||
for (const { options, onTransformCb } of loaders) { | ||
@@ -1049,14 +1050,20 @@ if (!checkFilter(options)) | ||
if (onTransformCb) { | ||
result = result || {}; | ||
result.contents = result.contents || await import_fs2.default.promises.readFile(args.path, "utf8"); | ||
const _result = await onTransformCb({ | ||
const newArgs = { | ||
...result, | ||
...args, | ||
contents: result.contents | ||
}); | ||
if (_result && _result.contents) | ||
async getContents() { | ||
if (result == null ? void 0 : result.contents) | ||
return result.contents; | ||
if (fsContentsCache) | ||
return fsContentsCache; | ||
return fsContentsCache = await import_fs2.default.promises.readFile(args.path, "utf8"); | ||
} | ||
}; | ||
const _result = await onTransformCb(newArgs); | ||
if (_result == null ? void 0 : _result.contents) | ||
result = _result; | ||
} | ||
} | ||
return result; | ||
if (result == null ? void 0 : result.contents) | ||
return result; | ||
}); | ||
@@ -1073,12 +1080,14 @@ } | ||
return (plugin) => { | ||
if (plugin.esbuild?.setup) | ||
var _a; | ||
if ((_a = plugin.esbuild) == null ? void 0 : _a.setup) | ||
return plugin.esbuild.setup; | ||
return (build2) => { | ||
var _a2, _b, _c, _d; | ||
meta.build = build2; | ||
const { onStart, onEnd, onResolve, onLoad, onTransform, initialOptions } = build2; | ||
const onResolveFilter = plugin.esbuild?.onResolveFilter ?? /.*/; | ||
const onLoadFilter = plugin.esbuild?.onLoadFilter ?? /.*/; | ||
const loader = plugin.esbuild?.loader ?? guessLoader; | ||
const onResolveFilter = ((_a2 = plugin.esbuild) == null ? void 0 : _a2.onResolveFilter) ?? /.*/; | ||
const onLoadFilter = ((_b = plugin.esbuild) == null ? void 0 : _b.onLoadFilter) ?? /.*/; | ||
const loader = ((_c = plugin.esbuild) == null ? void 0 : _c.loader) ?? guessLoader; | ||
const context = createBuildContext(initialOptions); | ||
if (plugin.esbuild?.config) | ||
if ((_d = plugin.esbuild) == null ? void 0 : _d.config) | ||
plugin.esbuild.config.call(context, initialOptions); | ||
@@ -1097,3 +1106,4 @@ if (plugin.buildStart) | ||
onResolve({ filter: onResolveFilter }, async (args) => { | ||
if (initialOptions.external?.includes(args.path)) { | ||
var _a3; | ||
if ((_a3 = initialOptions.external) == null ? void 0 : _a3.includes(args.path)) { | ||
return void 0; | ||
@@ -1169,3 +1179,3 @@ } | ||
const resolveDir = import_path3.default.dirname(args.path); | ||
let code = args.contents; | ||
let code = await args.getContents(); | ||
let map; | ||
@@ -1504,4 +1514,5 @@ const result = await plugin.transform.call(mixedContext, code, id); | ||
addWatchFile(file) { | ||
var _a; | ||
fileDependencies.add(file); | ||
resolveContext.fileDependencies?.add(file); | ||
(_a = resolveContext.fileDependencies) == null ? void 0 : _a.add(file); | ||
}, | ||
@@ -1508,0 +1519,0 @@ getWatchFiles() { |
@@ -96,7 +96,8 @@ "use strict"; | ||
async function load(source, map) { | ||
var _a; | ||
const callback = this.async(); | ||
const { unpluginName } = this.query; | ||
const plugin = this._compiler?.$unpluginContext[unpluginName]; | ||
const plugin = (_a = this._compiler) == null ? void 0 : _a.$unpluginContext[unpluginName]; | ||
const id = this.resource; | ||
if (!plugin?.load || !id) | ||
if (!(plugin == null ? void 0 : plugin.load) || !id) | ||
return callback(null, source, map); | ||
@@ -103,0 +104,0 @@ if (plugin.loadInclude && !plugin.loadInclude(id)) |
@@ -87,2 +87,3 @@ "use strict"; | ||
async function transform(source, map) { | ||
var _a; | ||
const callback = this.async(); | ||
@@ -97,4 +98,4 @@ let unpluginName; | ||
const id = this.resource; | ||
const plugin = this._compiler?.$unpluginContext[unpluginName]; | ||
if (!plugin?.transform) | ||
const plugin = (_a = this._compiler) == null ? void 0 : _a.$unpluginContext[unpluginName]; | ||
if (!(plugin == null ? void 0 : plugin.transform)) | ||
return callback(null, source, map); | ||
@@ -101,0 +102,0 @@ const context = createContext(this); |
@@ -104,7 +104,8 @@ "use strict"; | ||
async function load(source, map) { | ||
var _a; | ||
const callback = this.async(); | ||
const { unpluginName } = this.query; | ||
const plugin = this._compiler?.$unpluginContext[unpluginName]; | ||
const plugin = (_a = this._compiler) == null ? void 0 : _a.$unpluginContext[unpluginName]; | ||
let id = this.resource; | ||
if (!plugin?.load || !id) | ||
if (!(plugin == null ? void 0 : plugin.load) || !id) | ||
return callback(null, source, map); | ||
@@ -111,0 +112,0 @@ if (id.startsWith(plugin.__virtualModulePrefix)) |
@@ -95,2 +95,3 @@ "use strict"; | ||
async function transform(source, map) { | ||
var _a; | ||
const callback = this.async(); | ||
@@ -104,4 +105,4 @@ let unpluginName; | ||
} | ||
const plugin = this._compiler?.$unpluginContext[unpluginName]; | ||
if (!plugin?.transform) | ||
const plugin = (_a = this._compiler) == null ? void 0 : _a.$unpluginContext[unpluginName]; | ||
if (!(plugin == null ? void 0 : plugin.transform)) | ||
return callback(null, source, map); | ||
@@ -108,0 +109,0 @@ const context = createContext(this); |
{ | ||
"name": "unplugin", | ||
"version": "1.8.2", | ||
"version": "1.8.3", | ||
"packageManager": "pnpm@8.15.4", | ||
@@ -27,2 +27,5 @@ "description": "Unified plugin system for build tools", | ||
], | ||
"engines": { | ||
"node": ">=14.0.0" | ||
}, | ||
"scripts": { | ||
@@ -29,0 +32,0 @@ "build": "tsup", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
153332
4258