Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cut a new release 🚀 #1044

Merged
merged 5 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
38 changes: 18 additions & 20 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,29 +1,27 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
// https://github.com/microsoft/vscode-dev-containers/tree/v0.222.0/containers/javascript-node
{
"name": "Node.js",
"build": {
"dockerfile": "Dockerfile",
// Update 'VARIANT' to pick a Node version: 16, 14, 12.
// Append -bullseye or -buster to pin to an OS version.
// Use -bullseye variants on local arm64/Apple Silicon.
"args": { "VARIANT": "16-bullseye" }
},
"name": "Node.js",
"build": {
"dockerfile": "Dockerfile",
// Update 'VARIANT' to pick a Node version: 16, 14, 12.
// Append -bullseye or -buster to pin to an OS version.
// Use -bullseye variants on local arm64/Apple Silicon.
"args": { "VARIANT": "16-bullseye" }
},

// Set *default* container specific settings.json values on container create.
"settings": {},
// Set *default* container specific settings.json values on container create.
"settings": {},

// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"dbaeumer.vscode-eslint"
],
// Add the IDs of extensions you want installed when the container is created.
"extensions": ["dbaeumer.vscode-eslint"],

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],
// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],

// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": "pnpm install",
// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": "pnpm install",

// Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "node"
// Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "node"
}
37 changes: 37 additions & 0 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Fix

on:
push:
branches-ignore:
- 'main'
- 'dev'

jobs:
format:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- uses: pnpm/action-setup@v2
name: Install pnpm

- uses: actions/setup-node@v4
with:
node-version: lts/*
cache: pnpm

- run: pnpm i

- name: Format
run: pnpm run format

- name: Commit files and push
continue-on-error: true
if: ${{ github.ref != 'refs/heads/main' && github.ref != 'refs/heads/dev' }}
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git add --all
git commit -m "chore(ci): [bot] format code"
git push
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pnpm-lock.yaml
.cache
dist
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"singleQuote": true,
"semi": false
}
}
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ Head over to the [discussions](https://github.com/egoist/tsup/discussions) to sh

## Sponsors


<p align="center">
<a href="https://chromatic.com" target="_blank"><picture>
<source media="(prefers-color-scheme: dark)" width="500" srcset="https://fastly.jsdelivr.net/gh/egoist-bot/images@main/uPic/Group 2 (2).png">
Expand Down
2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ If you have multiple entry files, each entry will get a corresponding `.d.ts` fi

Note that `--dts` does not resolve external (aka in `node_modules`) types used in the `.d.ts` file, if that's somehow a requirement, try the experimental `--dts-resolve` flag instead.

Since tsup version 7.4.0, you can also use `--experimental-dts` flag to generate declaration files. This flag use [@microsoft/api-extractor](https://www.npmjs.com/package/@microsoft/api-extractor) to generate declaration files, which is more reliable than the previous `--dts` flag. It's still experimental and we are looking for feedbacks.
Since tsup version 8.0.0, you can also use `--experimental-dts` flag to generate declaration files. This flag use [@microsoft/api-extractor](https://www.npmjs.com/package/@microsoft/api-extractor) to generate declaration files, which is more reliable than the previous `--dts` flag. It's still experimental and we are looking for feedbacks.

To use `--experimental-dts`, you would need to install `@microsoft/api-extractor`, as it's a peer dependency of tsup:

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"build": "tsup src/cli-*.ts src/index.ts src/rollup.ts --clean --splitting",
"prepublishOnly": "npm run build",
"test": "npm run build && npm run test-only",
"format": "prettier --write .",
"test-only": "vitest run",
"build-fast": "npm run build -- --no-dts"
},
Expand Down
4 changes: 1 addition & 3 deletions renovate.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
{
"extends": [
"config:base"
]
"extends": ["config:base"]
}
1 change: 0 additions & 1 deletion schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
}
}
]

}
}
},
Expand Down
15 changes: 14 additions & 1 deletion src/api-extractor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
defaultOutExtension,
ensureTempDeclarationDir,
getApiExtractor,
removeFiles,
toAbsolutePath,
writeFileSync,
} from './utils'
Expand Down Expand Up @@ -123,13 +124,24 @@ async function rollupDtsFiles(
sourceFileName = toAbsolutePath(sourceFileName)
const outFileName = path.join(outDir, out + dtsExtension)

// Find all declarations that are exported from the current source file
const currentExports = exports.filter(
(declaration) => declaration.sourceFileName === sourceFileName
)

writeFileSync(
outFileName,
formatDistributionExports(exports, outFileName, dtsOutputFilePath)
formatDistributionExports(currentExports, outFileName, dtsOutputFilePath)
)
}
}

function cleanDtsFiles(options: NormalizedOptions) {
if (options.clean) {
removeFiles(['**/*.d.{ts,mts,cts}'], options.outDir)
}
}

export async function runDtsRollup(
options: NormalizedOptions,
exports?: ExportDeclaration[]
Expand All @@ -144,6 +156,7 @@ export async function runDtsRollup(
if (!exports) {
throw new Error('Unexpected internal error: dts exports is not define')
}
cleanDtsFiles(options)
for (const format of options.format) {
await rollupDtsFiles(options, exports, format)
}
Expand Down
5 changes: 4 additions & 1 deletion src/cli-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ export async function main(options: Options = {}) {
.option('--dts [entry]', 'Generate declaration file')
.option('--dts-resolve', 'Resolve externals types used for d.ts files')
.option('--dts-only', 'Emit declaration files only')
.option('--experimental-dts [entry]', 'Generate declaration file (experimental)')
.option(
'--experimental-dts [entry]',
'Generate declaration file (experimental)'
)
.option(
'--sourcemap [inline]',
'Generate external sourcemap, or inline source: --sourcemap inline'
Expand Down
27 changes: 15 additions & 12 deletions src/esbuild/node-protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,20 @@ import { Plugin } from 'esbuild'
* https://nodejs.org/api/esm.html#node-imports
*/
export const nodeProtocolPlugin = (): Plugin => {
const nodeProtocol = 'node:'
const nodeProtocol = 'node:'

return {
name: 'node-protocol-plugin',
setup({ onResolve }) {
onResolve({
filter: /^node:/,
}, ({ path }) => ({
path: path.slice(nodeProtocol.length),
external: true
}))
}
}
return {
name: 'node-protocol-plugin',
setup({ onResolve }) {
onResolve(
{
filter: /^node:/,
},
({ path }) => ({
path: path.slice(nodeProtocol.length),
external: true,
})
)
},
}
}
2 changes: 1 addition & 1 deletion src/exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export function formatDistributionExports(
if (!importPath.match(/^\.+\//)) {
importPath = './' + importPath
}

let seen = {
named: new Set<string>(),
module: new Set<string>(),
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ export async function build(_options: Options) {
: []
// .d.ts files are removed in the `dtsTask` instead
// `dtsTask` is a separate process, which might start before `mainTasks`
if (options.dts) {
if (options.dts || options.experimentalDts) {
extraPatterns.unshift('!**/*.d.{ts,cts,mts}')
}
await removeFiles(['**/*', ...extraPatterns], options.outDir)
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/tree-shaking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const treeShakingPlugin = ({
name,
silent,
}: {
treeshake?: TreeshakingStrategy,
treeshake?: TreeshakingStrategy
name?: string
silent?: boolean
}): Plugin => {
Expand Down Expand Up @@ -46,7 +46,7 @@ export const treeShakingPlugin = ({
format: this.format,
file: 'out.js',
sourcemap: !!this.options.sourcemap,
name
name,
})

for (const file of result.output) {
Expand Down
1 change: 1 addition & 0 deletions src/rollup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ const getRollupConfig = async (
banner: dtsOptions.banner,
footer: dtsOptions.footer,
entryFileNames: `[name]${outputExtension}`,
chunkFileNames: `[name]-[hash]${outputExtension}`,
plugins: [
format === 'cjs' && options.cjsInterop && fixCjsExport,
].filter(Boolean),
Expand Down
78 changes: 14 additions & 64 deletions test/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -340,44 +340,22 @@ export { }
// dist/index.d.mts
//////////////////////////////////////////////////////////////////////

export { render } from './_tsup-dts-rollup';
export { ClientRenderOptions } from './_tsup-dts-rollup';
export { sharedFunction } from './_tsup-dts-rollup';
export { sharedType } from './_tsup-dts-rollup';
export { VERSION } from './_tsup-dts-rollup';
export { default_alias as default } from './_tsup-dts-rollup';
export { ServerRenderOptions } from './_tsup-dts-rollup';
export { serverConstant } from './_tsup-dts-rollup';
export { serverConstantAlias } from './_tsup-dts-rollup';
export { ServerClass } from './_tsup-dts-rollup';
export { ServerThirdPartyNamespace } from './_tsup-dts-rollup';
export { renderToString } from './_tsup-dts-rollup';
export { renderToNodeStream } from './_tsup-dts-rollup';
export { renderToStaticMarkup } from './_tsup-dts-rollup';
export { renderToStaticNodeStream } from './_tsup-dts-rollup';
export { version } from './_tsup-dts-rollup';
export { render_alias_1 as render } from './_tsup-dts-rollup';
export { ClientRenderOptions_alias_1 as ClientRenderOptions } from './_tsup-dts-rollup';
export { sharedFunction_alias_1 as sharedFunction } from './_tsup-dts-rollup';
export { sharedType_alias_1 as sharedType } from './_tsup-dts-rollup';


//////////////////////////////////////////////////////////////////////
// dist/index.d.ts
//////////////////////////////////////////////////////////////////////

export { render } from './_tsup-dts-rollup';
export { ClientRenderOptions } from './_tsup-dts-rollup';
export { sharedFunction } from './_tsup-dts-rollup';
export { sharedType } from './_tsup-dts-rollup';
export { VERSION } from './_tsup-dts-rollup';
export { default_alias as default } from './_tsup-dts-rollup';
export { ServerRenderOptions } from './_tsup-dts-rollup';
export { serverConstant } from './_tsup-dts-rollup';
export { serverConstantAlias } from './_tsup-dts-rollup';
export { ServerClass } from './_tsup-dts-rollup';
export { ServerThirdPartyNamespace } from './_tsup-dts-rollup';
export { renderToString } from './_tsup-dts-rollup';
export { renderToNodeStream } from './_tsup-dts-rollup';
export { renderToStaticMarkup } from './_tsup-dts-rollup';
export { renderToStaticNodeStream } from './_tsup-dts-rollup';
export { version } from './_tsup-dts-rollup';
export { render_alias_1 as render } from './_tsup-dts-rollup';
export { ClientRenderOptions_alias_1 as ClientRenderOptions } from './_tsup-dts-rollup';
export { sharedFunction_alias_1 as sharedFunction } from './_tsup-dts-rollup';
export { sharedType_alias_1 as sharedType } from './_tsup-dts-rollup';


//////////////////////////////////////////////////////////////////////
Expand All @@ -388,18 +366,6 @@ export { render } from './_tsup-dts-rollup';
export { ClientRenderOptions } from './_tsup-dts-rollup';
export { sharedFunction } from './_tsup-dts-rollup';
export { sharedType } from './_tsup-dts-rollup';
export { VERSION } from './_tsup-dts-rollup';
export { default_alias as default } from './_tsup-dts-rollup';
export { ServerRenderOptions } from './_tsup-dts-rollup';
export { serverConstant } from './_tsup-dts-rollup';
export { serverConstantAlias } from './_tsup-dts-rollup';
export { ServerClass } from './_tsup-dts-rollup';
export { ServerThirdPartyNamespace } from './_tsup-dts-rollup';
export { renderToString } from './_tsup-dts-rollup';
export { renderToNodeStream } from './_tsup-dts-rollup';
export { renderToStaticMarkup } from './_tsup-dts-rollup';
export { renderToStaticNodeStream } from './_tsup-dts-rollup';
export { version } from './_tsup-dts-rollup';


//////////////////////////////////////////////////////////////////////
Expand All @@ -410,35 +376,21 @@ export { render } from './_tsup-dts-rollup';
export { ClientRenderOptions } from './_tsup-dts-rollup';
export { sharedFunction } from './_tsup-dts-rollup';
export { sharedType } from './_tsup-dts-rollup';
export { VERSION } from './_tsup-dts-rollup';
export { default_alias as default } from './_tsup-dts-rollup';
export { ServerRenderOptions } from './_tsup-dts-rollup';
export { serverConstant } from './_tsup-dts-rollup';
export { serverConstantAlias } from './_tsup-dts-rollup';
export { ServerClass } from './_tsup-dts-rollup';
export { ServerThirdPartyNamespace } from './_tsup-dts-rollup';
export { renderToString } from './_tsup-dts-rollup';
export { renderToNodeStream } from './_tsup-dts-rollup';
export { renderToStaticMarkup } from './_tsup-dts-rollup';
export { renderToStaticNodeStream } from './_tsup-dts-rollup';
export { version } from './_tsup-dts-rollup';


//////////////////////////////////////////////////////////////////////
// dist/server/index.d.mts
//////////////////////////////////////////////////////////////////////

export { render } from '../_tsup-dts-rollup';
export { ClientRenderOptions } from '../_tsup-dts-rollup';
export { sharedFunction } from '../_tsup-dts-rollup';
export { sharedType } from '../_tsup-dts-rollup';
export { VERSION } from '../_tsup-dts-rollup';
export { render_alias_2 as render } from '../_tsup-dts-rollup';
export { default_alias as default } from '../_tsup-dts-rollup';
export { ServerRenderOptions } from '../_tsup-dts-rollup';
export { serverConstant } from '../_tsup-dts-rollup';
export { serverConstantAlias } from '../_tsup-dts-rollup';
export { ServerClass } from '../_tsup-dts-rollup';
export { ServerThirdPartyNamespace } from '../_tsup-dts-rollup';
export { sharedFunction_alias_2 as sharedFunction } from '../_tsup-dts-rollup';
export { sharedType_alias_2 as sharedType } from '../_tsup-dts-rollup';
export { renderToString } from '../_tsup-dts-rollup';
export { renderToNodeStream } from '../_tsup-dts-rollup';
export { renderToStaticMarkup } from '../_tsup-dts-rollup';
Expand All @@ -450,17 +402,15 @@ export { version } from '../_tsup-dts-rollup';
// dist/server/index.d.ts
//////////////////////////////////////////////////////////////////////

export { render } from '../_tsup-dts-rollup';
export { ClientRenderOptions } from '../_tsup-dts-rollup';
export { sharedFunction } from '../_tsup-dts-rollup';
export { sharedType } from '../_tsup-dts-rollup';
export { VERSION } from '../_tsup-dts-rollup';
export { render_alias_2 as render } from '../_tsup-dts-rollup';
export { default_alias as default } from '../_tsup-dts-rollup';
export { ServerRenderOptions } from '../_tsup-dts-rollup';
export { serverConstant } from '../_tsup-dts-rollup';
export { serverConstantAlias } from '../_tsup-dts-rollup';
export { ServerClass } from '../_tsup-dts-rollup';
export { ServerThirdPartyNamespace } from '../_tsup-dts-rollup';
export { sharedFunction_alias_2 as sharedFunction } from '../_tsup-dts-rollup';
export { sharedType_alias_2 as sharedType } from '../_tsup-dts-rollup';
export { renderToString } from '../_tsup-dts-rollup';
export { renderToNodeStream } from '../_tsup-dts-rollup';
export { renderToStaticMarkup } from '../_tsup-dts-rollup';
Expand Down