Skip to content

Commit

Permalink
fix: patch bundle-require
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Apr 22, 2024
1 parent e3fcad5 commit 179bc64
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 62 deletions.
4 changes: 4 additions & 0 deletions build.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@ export default defineBuildConfig({
'src/cli.ts',
],
clean: false,
// TODO: remove this when https://github.com/egoist/bundle-require/pull/41 is merged
rollup: {
inlineDependencies: true,
},
})
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@
"eslint": "^8.50.0 || ^9.0.0"
},
"dependencies": {
"bundle-require": "^4.0.2",
"cac": "^6.7.14",
"chokidar": "^3.6.0",
"esbuild": "^0.20.2",
"fast-glob": "^3.3.2",
"find-up": "^7.0.0",
"get-port-please": "^3.1.2",
"h3": "^1.11.1",
"load-tsconfig": "^0.2.5",
"minimatch": "^9.0.4",
"mrmime": "^2.0.0",
"open": "^10.1.0",
Expand All @@ -65,6 +65,7 @@
"@unocss/eslint-config": "^0.59.4",
"@unocss/nuxt": "^0.59.4",
"@vueuse/nuxt": "^10.9.0",
"bundle-require": "^4.0.2",
"eslint": "^9.1.0",
"floating-vue": "^5.2.2",
"fuse.js": "^7.0.0",
Expand All @@ -78,6 +79,11 @@
"unbuild": "^2.0.0",
"vue-tsc": "^2.0.14"
},
"pnpm": {
"patchedDependencies": {
"bundle-require@4.0.2": "patches/bundle-require@4.0.2.patch"
}
},
"simple-git-hooks": {
"pre-commit": "pnpm lint-staged"
},
Expand Down
1 change: 1 addition & 0 deletions patches/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Remove the `bundle-require` patch and move it to dependencies after https://github.com/egoist/bundle-require/pull/41 get merged
78 changes: 78 additions & 0 deletions patches/bundle-require@4.0.2.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
diff --git a/dist/index.cjs b/dist/index.cjs
index f501766b71e3c856f97c37aa37608bbec53fa281..cae0c5b63891abcfa2b3665d40f1e65ca64455c5 100644
--- a/dist/index.cjs
+++ b/dist/index.cjs
@@ -82,6 +82,7 @@ var DIRNAME_VAR_NAME = "__injected_dirname__";
var FILENAME_VAR_NAME = "__injected_filename__";
var IMPORT_META_URL_VAR_NAME = "__injected_import_meta_url__";
var JS_EXT_RE = /\.([mc]?[tj]s|[tj]sx)$/;
+var PATH_NODE_MODULES_RE = /[\/\\]node_modules[\/\\]/;
function inferLoader(ext) {
if (ext === ".mjs" || ext === ".cjs")
return "js";
@@ -116,9 +117,6 @@ var externalPlugin = ({
name: "bundle-require:external",
setup(ctx) {
ctx.onResolve({ filter: /.*/ }, async (args) => {
- if (args.path[0] === "." || import_path2.default.isAbsolute(args.path)) {
- return;
- }
if (match(args.path, external)) {
return {
external: true
@@ -127,6 +125,16 @@ var externalPlugin = ({
if (match(args.path, notExternal)) {
return;
}
+ if (args.path.match(PATH_NODE_MODULES_RE)) {
+ const resolved = args.path[0] === "." ? import_path2.default.resolve(args.resolveDir, args.path) : args.path;
+ return {
+ path: resolved,
+ external: true
+ };
+ }
+ if (args.path[0] === "." || import_path2.default.isAbsolute(args.path)) {
+ return;
+ }
return {
external: true
};
diff --git a/dist/index.js b/dist/index.js
index 214ed416d1e739f0a4ebb0b9f2b017b174b76b6d..aa515a5cf0223bedd7f9316d47ddeeac847caa13 100644
--- a/dist/index.js
+++ b/dist/index.js
@@ -49,6 +49,7 @@ var DIRNAME_VAR_NAME = "__injected_dirname__";
var FILENAME_VAR_NAME = "__injected_filename__";
var IMPORT_META_URL_VAR_NAME = "__injected_import_meta_url__";
var JS_EXT_RE = /\.([mc]?[tj]s|[tj]sx)$/;
+var PATH_NODE_MODULES_RE = /[\/\\]node_modules[\/\\]/;
function inferLoader(ext) {
if (ext === ".mjs" || ext === ".cjs")
return "js";
@@ -83,9 +84,6 @@ var externalPlugin = ({
name: "bundle-require:external",
setup(ctx) {
ctx.onResolve({ filter: /.*/ }, async (args) => {
- if (args.path[0] === "." || path2.isAbsolute(args.path)) {
- return;
- }
if (match(args.path, external)) {
return {
external: true
@@ -94,6 +92,16 @@ var externalPlugin = ({
if (match(args.path, notExternal)) {
return;
}
+ if (args.path.match(PATH_NODE_MODULES_RE)) {
+ const resolved = args.path[0] === "." ? path2.resolve(args.resolveDir, args.path) : args.path;
+ return {
+ path: resolved,
+ external: true
+ };
+ }
+ if (args.path[0] === "." || path2.isAbsolute(args.path)) {
+ return;
+ }
return {
external: true
};
78 changes: 17 additions & 61 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 179bc64

Please sign in to comment.