Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions assets/cjs_shims.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
// if we export it as `const importMetaUrl = ... __filename ...`
// But using a function will not cause this issue

const getImportMetaUrl = () =>
typeof document === "undefined"
? new URL(`file:${__filename}`).href
: (document.currentScript && document.currentScript.tagName.toUpperCase() === 'SCRIPT')
? document.currentScript.src
: new URL("main.js", document.baseURI).href;
const getImportMetaUrl = () =>
typeof document === 'undefined'
? new URL(`file:${__filename}`).href
: document.currentScript &&
document.currentScript.tagName.toUpperCase() === 'SCRIPT'
? document.currentScript.src
: new URL('main.js', document.baseURI).href

export const importMetaUrl = /* @__PURE__ */ getImportMetaUrl()
17 changes: 9 additions & 8 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,7 @@ When you use legacy TypeScript decorator by enabling `emitDecoratorMetadata` in
decorators. In this case, you can give extra swc configuration in the `tsup.config.ts` file.

For example, if you have to define `useDefineForClassFields`, you can do that as follows:

```ts
import { defineConfig } from 'tsup'

Expand All @@ -626,10 +627,10 @@ export default defineConfig({
swc: {
jsc: {
transform: {
useDefineForClassFields: true
}
}
}
useDefineForClassFields: true,
},
},
},
})
```

Expand All @@ -648,9 +649,9 @@ Note: some SWC options cannot be configured:
"keepClassNames": true,
"target": "es2022"
}
```
```

You can also define a custom `.swcrc` configuration file. Just set `swcrc` to `true`
You can also define a custom `.swcrc` configuration file. Just set `swcrc` to `true`
in `tsup.config.ts` to allow SWC plugin to discover automatically your custom swc config file.

```ts
Expand All @@ -662,8 +663,8 @@ export default defineConfig({
sourcemap: true,
clean: true,
swc: {
swcrc: true
}
swcrc: true,
},
})
```

Expand Down
5 changes: 4 additions & 1 deletion src/esbuild/swc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ import type { Logger } from '../log'

export type SwcPluginConfig = { logger: Logger } & Options

export const swcPlugin = ({ logger, ...swcOptions }: SwcPluginConfig): Plugin => {
export const swcPlugin = ({
logger,
...swcOptions
}: SwcPluginConfig): Plugin => {
return {
name: 'swc',

Expand Down
2 changes: 1 addition & 1 deletion src/lib/report-size.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import colors from 'picocolors'
import type { Logger } from '../log'

const prettyBytes = (bytes: number) => {
if (bytes === 0) return '0 B'
if (bytes < 1024) return `${bytes} B`
const unit = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
const exp = Math.floor(Math.log(bytes) / Math.log(1024))
return `${(bytes / 1024 ** exp).toFixed(2)} ${unit[exp]}`
Expand Down
4 changes: 2 additions & 2 deletions src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,8 @@ export type Options = {
* @default true
*/
removeNodeProtocol?: boolean
swc?: SwcPluginConfig;

swc?: SwcPluginConfig
}

export interface NormalizedExperimentalDtsConfig {
Expand Down
2 changes: 1 addition & 1 deletion vitest.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ export default defineConfig({
test: {
testTimeout: 50000,
globalSetup: 'vitest-global.ts',
include: ["test/*.test.ts", "src/**/*.test.ts"]
include: ['test/*.test.ts', 'src/**/*.test.ts'],
},
})