diff --git a/packages/pack/src/actions/main.ts b/packages/pack/src/actions/main.ts index 3630367..1ec3323 100644 --- a/packages/pack/src/actions/main.ts +++ b/packages/pack/src/actions/main.ts @@ -59,7 +59,7 @@ module.exports = async function action(specifiedEntries: string[], options: any } = {}) => { let eachOutExt = eachOptions.ext || eachOptions.outfile && upath.extname(eachOptions.outfile) || undefined const outExtension = { '.css': '.css' } - const external = [ + let external = [ ...externalDependencies, ...options.external ] @@ -89,6 +89,9 @@ module.exports = async function action(specifiedEntries: string[], options: any } }) } + if (eachOptions.bundle && options.forceIifeBundle) { + external = [] + } const eachOutdir = eachOptions.outdir || options.outdir /** diff --git a/packages/pack/tests/force-iife-bundle/package.json b/packages/pack/tests/force-iife-bundle/package.json new file mode 100644 index 0000000..271ae16 --- /dev/null +++ b/packages/pack/tests/force-iife-bundle/package.json @@ -0,0 +1,12 @@ +{ + "name": "@test/force-iife-bundle", + "version": "1.0.0", + "private": true, + "browser": "./dist/iife.bundle.js", + "files": [ + "dist" + ], + "dependencies": { + "server-only": "^0.0.1" + } +} \ No newline at end of file diff --git a/packages/pack/tests/force-iife-bundle/src/iife.ts b/packages/pack/tests/force-iife-bundle/src/iife.ts new file mode 100644 index 0000000..2fac8dc --- /dev/null +++ b/packages/pack/tests/force-iife-bundle/src/iife.ts @@ -0,0 +1 @@ +import 'server-only' \ No newline at end of file diff --git a/packages/pack/tests/force-iife-bundle/test.ts b/packages/pack/tests/force-iife-bundle/test.ts new file mode 100644 index 0000000..dcbff5e --- /dev/null +++ b/packages/pack/tests/force-iife-bundle/test.ts @@ -0,0 +1,7 @@ +import { execSync } from 'node:child_process' +import { expectFileIncludes } from '../../../../utils/expect-file-includes' + +it('force to bundle iife', () => { + execSync('tsx ../../../techor/src/bin pack', { cwd: __dirname, stdio: 'pipe' }) + expectFileIncludes('dist/iife.bundle.js', ['(()=>{throw new Error("This module cannot be imported from a Client Component module. It should only be used from a Server Component.");})();'], { cwd: __dirname }) +}) \ No newline at end of file diff --git a/packages/pack/tests/force-iife-bundle/tsconfig.json b/packages/pack/tests/force-iife-bundle/tsconfig.json new file mode 100644 index 0000000..b94c20e --- /dev/null +++ b/packages/pack/tests/force-iife-bundle/tsconfig.json @@ -0,0 +1,13 @@ +{ + "extends": "../../../../tsconfig.json", + "compilerOptions": { + "baseUrl": ".", + "outDir": "dist", + }, + "include": [ + "src/**/*" + ], + "exclude": [ + "src/**/*.test.ts" + ] +} \ No newline at end of file diff --git a/packages/pack/tests/pnpm-lock.yaml b/packages/pack/tests/pnpm-lock.yaml index 6829e5e..03040b7 100644 --- a/packages/pack/tests/pnpm-lock.yaml +++ b/packages/pack/tests/pnpm-lock.yaml @@ -49,6 +49,12 @@ importers: specifier: '' version: 2.4.6 + force-iife-bundle: + dependencies: + server-only: + specifier: ^0.0.1 + version: 0.0.1 + mjs: dependencies: server-only: diff --git a/packages/techor/src/bin/index.ts b/packages/techor/src/bin/index.ts index ee768d6..9a36ee2 100755 --- a/packages/techor/src/bin/index.ts +++ b/packages/techor/src/bin/index.ts @@ -34,6 +34,7 @@ program.command('pack [entryPaths...]') .option('--declare', 'Emit typescript declarations') .option('--no-minify', 'OFF: Minify the generated code') .option('--no-clean', 'OFF: Clean up the previous output directory before the build starts') + .option('--no-force-iife-bundle', 'OFF: No external packages when the output format is iife') .action(async function (args, options) { try { const action = require(