Skip to content

Commit

Permalink
Add(Pack): Support for no-force-iife-bundle option
Browse files Browse the repository at this point in the history
  • Loading branch information
1aron committed Jan 8, 2024
1 parent d729dc5 commit ebc787a
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/pack/src/actions/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
]
Expand Down Expand Up @@ -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

/**
Expand Down
12 changes: 12 additions & 0 deletions packages/pack/tests/force-iife-bundle/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
1 change: 1 addition & 0 deletions packages/pack/tests/force-iife-bundle/src/iife.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import 'server-only'
7 changes: 7 additions & 0 deletions packages/pack/tests/force-iife-bundle/test.ts
Original file line number Diff line number Diff line change
@@ -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 })
})
13 changes: 13 additions & 0 deletions packages/pack/tests/force-iife-bundle/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": "../../../../tsconfig.json",
"compilerOptions": {
"baseUrl": ".",
"outDir": "dist",
},
"include": [
"src/**/*"
],
"exclude": [
"src/**/*.test.ts"
]
}
6 changes: 6 additions & 0 deletions packages/pack/tests/pnpm-lock.yaml

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

1 change: 1 addition & 0 deletions packages/techor/src/bin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit ebc787a

Please sign in to comment.