@storm-stack/core
Version:
A build toolkit and runtime used by Storm Software in TypeScript applications
119 lines (116 loc) • 4.53 kB
JavaScript
;
var chunk3ONWID2V_cjs = require('./chunk-3ONWID2V.cjs');
var bundleRequire = require('bundle-require');
var NON_NODE_MODULE_REGEX = /^[A-Z]:[/\\]|^\.{0,2}\/|^\.{1,2}$/;
var resolverPlugin = /* @__PURE__ */ chunk3ONWID2V_cjs.__name((context, options = {}) => {
return {
name: "storm-stack:resolver",
setup(build) {
const skipNodeModulesBundle = options.skipNodeModulesBundle ?? context.options.skipNodeModulesBundle;
const external = options.external ?? context.options.external ?? [];
const noExternal = options.noExternal ?? context.options.noExternal ?? [];
if (skipNodeModulesBundle) {
const resolvePatterns = bundleRequire.tsconfigPathsToRegExp(context.tsconfig.options.paths ?? []);
build.onResolve({
filter: /.*/
}, (args) => {
if (args.path) {
if (context.vfs.isVirtualFile(args.path, {
paths: [
args.resolveDir
]
}) || args.importer && context.vfs.isVirtualFile(args.importer)) {
const resolvedPath = context.vfs.resolvePath(args.path, {
paths: [
args.resolveDir
]
});
if (resolvedPath) {
return {
path: resolvedPath,
external: context.options.projectType !== "application"
};
}
}
if (context.vfs.isTsconfigPath(args.path)) {
const tsconfigPath = context.vfs.resolveTsconfigPath(args.path);
const tsconfigPathPackage = context.vfs.resolveTsconfigPathPackage(args.path);
if (tsconfigPath && tsconfigPathPackage) {
return {
path: tsconfigPath,
external: !noExternal.includes(tsconfigPathPackage) && (external.includes(tsconfigPathPackage) || context.options.projectType !== "application")
};
}
}
if (bundleRequire.match(args.path, resolvePatterns) || bundleRequire.match(args.path, noExternal) || args.path.startsWith("internal:") || args.path.startsWith("virtual:")) {
return;
}
if (bundleRequire.match(args.path, external) || args.path.startsWith("node:")) {
return {
external: true
};
}
if (!NON_NODE_MODULE_REGEX.test(args.path)) {
return {
path: args.path,
external: true
};
}
}
return;
});
} else {
build.onResolve({
filter: /.*/
}, (args) => {
if (args.path) {
if (context.vfs.isVirtualFile(args.path, {
paths: [
args.resolveDir
]
}) || args.importer && context.vfs.isVirtualFile(args.importer)) {
const resolvedPath = context.vfs.resolvePath(args.path, {
paths: [
args.resolveDir
]
});
if (resolvedPath) {
return {
path: resolvedPath,
external: context.options.projectType !== "application"
};
}
}
if (context.vfs.isTsconfigPath(args.path)) {
const tsconfigPath = context.vfs.resolveTsconfigPath(args.path);
const tsconfigPathPackage = context.vfs.resolveTsconfigPathPackage(args.path);
if (tsconfigPath && tsconfigPathPackage) {
return {
path: tsconfigPath,
external: !noExternal.includes(tsconfigPathPackage) && (external.includes(tsconfigPathPackage) || context.options.projectType !== "application")
};
}
}
if (bundleRequire.match(args.path, noExternal) || context.vfs.isRuntimeFile(args.path, {
paths: [
args.resolveDir,
args.importer
]
})) {
return;
}
if (bundleRequire.match(args.path, external) || args.path.startsWith("node:")) {
return {
external: true
};
}
}
return;
});
}
}
};
}, "resolverPlugin");
exports.resolverPlugin = resolverPlugin;
//# sourceMappingURL=chunk-J5FGHGMA.cjs.map
//# sourceMappingURL=chunk-J5FGHGMA.cjs.map