diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a5f1663..10e061d8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # CHANGELOG +## 0.81.1 + +- Duplicate .d.ts files into cjs + + ## 0.80.1 - Typescript 5.5.4 diff --git a/package.json b/package.json index 7bc7ab85..0d25e176 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ }, "sideEffects": false, "type": "module", - "version": "0.80.1", + "version": "0.81.0", "versions": { "git": "0.80.1", "npm": "0.80.1" diff --git a/packages/dev-test/package.json b/packages/dev-test/package.json index 55d6248a..46a58da2 100644 --- a/packages/dev-test/package.json +++ b/packages/dev-test/package.json @@ -15,7 +15,7 @@ }, "sideEffects": false, "type": "module", - "version": "0.80.1", + "version": "0.81.0", "main": "./index.js", "exports": { "./globals.d.ts": "./src/globals.d.ts" diff --git a/packages/dev-ts/package.json b/packages/dev-ts/package.json index 0ba8f572..f341033d 100644 --- a/packages/dev-ts/package.json +++ b/packages/dev-ts/package.json @@ -15,7 +15,7 @@ }, "sideEffects": false, "type": "module", - "version": "0.80.1", + "version": "0.81.0", "main": "./index.js", "exports": { "./globals.d.ts": "./src/globals.d.ts" diff --git a/packages/dev/package.json b/packages/dev/package.json index 15685758..073522a3 100644 --- a/packages/dev/package.json +++ b/packages/dev/package.json @@ -15,7 +15,7 @@ }, "sideEffects": false, "type": "module", - "version": "0.80.1", + "version": "0.81.0", "bin": { "polkadot-ci-ghact-build": "./scripts/polkadot-ci-ghact-build.mjs", "polkadot-ci-ghact-docs": "./scripts/polkadot-ci-ghact-docs.mjs", @@ -50,8 +50,8 @@ }, "dependencies": { "@eslint/js": "^8.56.0", - "@polkadot/dev-test": "^0.80.1", - "@polkadot/dev-ts": "^0.80.1", + "@polkadot/dev-test": "^0.81.0", + "@polkadot/dev-ts": "^0.81.0", "@rollup/plugin-alias": "^5.1.0", "@rollup/plugin-commonjs": "^25.0.7", "@rollup/plugin-dynamic-import-vars": "^2.1.2", diff --git a/packages/dev/scripts/polkadot-dev-build-ts.mjs b/packages/dev/scripts/polkadot-dev-build-ts.mjs index fc86ee8e..7a6e0f50 100755 --- a/packages/dev/scripts/polkadot-dev-build-ts.mjs +++ b/packages/dev/scripts/polkadot-dev-build-ts.mjs @@ -438,10 +438,12 @@ function relativePath (value) { function createMapEntry (rootDir, jsPath = '', noTypes) { jsPath = relativePath(jsPath); + const typesPath = jsPath.replace('.js', '.d.ts'); const cjsPath = jsPath.replace('./', './cjs/'); + const cjsTypesPath = typesPath.replace('./', './cjs/'); const hasCjs = fs.existsSync(path.join(rootDir, cjsPath)); - const typesPath = jsPath.replace('.js', '.d.ts'); - const hasTypes = !noTypes && jsPath.endsWith('.js') && fs.existsSync(path.join(rootDir, typesPath)); + const hasTypesCjs = fs.existsSync(path.join(rootDir, cjsTypesPath)); + const hasTypes = !hasTypesCjs && !noTypes && jsPath.endsWith('.js') && fs.existsSync(path.join(rootDir, typesPath)); const field = hasCjs ? { // As per TS, the types key needs to be first @@ -453,12 +455,21 @@ function createMapEntry (rootDir, jsPath = '', noTypes) { // bundler-specific path, eg. webpack & rollup ...( jsPath.endsWith('.js') - ? { module: jsPath } + ? hasTypesCjs + // eslint-disable-next-line sort-keys + ? { module: { types: typesPath, default: jsPath } } + : { module: jsPath } : {} ), - require: cjsPath, + require: hasTypesCjs + // eslint-disable-next-line sort-keys + ? { types: cjsTypesPath, default: cjsPath } + : cjsPath, + // eslint-disable-next-line sort-keys + default: hasTypesCjs // eslint-disable-next-line sort-keys - default: jsPath + ? { types: typesPath, default: jsPath } + : jsPath } : hasTypes ? { @@ -496,7 +507,10 @@ function copyBuildFiles (compileType, dir) { copyDirSync('src', 'build', ['.patch', '.js', '.cjs', '.mjs', '.json', '.d.ts', '.d.cts', '.d.mts', '.css', '.gif', '.hbs', '.md', '.jpg', '.png', '.rs', '.svg']); // copy all *.d.ts files - copyDirSync([path.join('../../build', dir, 'src'), path.join('../../build/packages', dir, 'src')], 'build', ['.d.ts']); + const dtsPaths = ['build-tsc', path.join('../../build', dir, 'src'), path.join('../../build/packages', dir, 'src')]; + + copyDirSync(dtsPaths, 'build', ['.d.ts']); + copyDirSync(dtsPaths, 'build/cjs', ['.d.ts']); // copy all from build-{babel|swc|tsc|...}-esm to build copyDirSync(`build-${compileType}-esm`, 'build'); @@ -787,6 +801,8 @@ function buildExports () { pkg.exports = listRoot .filter(([path, config]) => + // skip d.ts files + !path.endsWith('.d.ts') && // we handle the CJS path at the root below path !== './cjs/package.json' && // we don't export ./deno/* paths (e.g. wasm) @@ -1255,6 +1271,11 @@ async function buildJs (compileType, repoPath, dir, locals) { orderPackageJson(repoPath, dir, pkgJson); + // move the tsc-generated *.d.ts build files to build-tsc + if (fs.existsSync('build')) { + copyDirSync('build', 'build-tsc', ['.d.ts']); + } + if (!fs.existsSync(path.join(process.cwd(), '.skip-build'))) { const srcHeader = `// Copyright 2017-${new Date().getFullYear()} ${name} authors & contributors\n// SPDX-License-Identifier: Apache-2.0\n`; const genHeader = `${srcHeader}\n// Do not edit, auto-generated by @polkadot/dev\n`; diff --git a/yarn.lock b/yarn.lock index 9ef9143e..8871d890 100644 --- a/yarn.lock +++ b/yarn.lock @@ -433,7 +433,7 @@ __metadata: languageName: node linkType: hard -"@polkadot/dev-test@npm:^0.80.1, @polkadot/dev-test@workspace:packages/dev-test": +"@polkadot/dev-test@npm:^0.81.0, @polkadot/dev-test@workspace:packages/dev-test": version: 0.0.0-use.local resolution: "@polkadot/dev-test@workspace:packages/dev-test" dependencies: @@ -443,7 +443,7 @@ __metadata: languageName: unknown linkType: soft -"@polkadot/dev-ts@npm:^0.80.1, @polkadot/dev-ts@workspace:packages/dev-ts": +"@polkadot/dev-ts@npm:^0.81.0, @polkadot/dev-ts@workspace:packages/dev-ts": version: 0.0.0-use.local resolution: "@polkadot/dev-ts@workspace:packages/dev-ts" dependencies: @@ -458,8 +458,8 @@ __metadata: resolution: "@polkadot/dev@workspace:packages/dev" dependencies: "@eslint/js": "npm:^8.56.0" - "@polkadot/dev-test": "npm:^0.80.1" - "@polkadot/dev-ts": "npm:^0.80.1" + "@polkadot/dev-test": "npm:^0.81.0" + "@polkadot/dev-ts": "npm:^0.81.0" "@rollup/plugin-alias": "npm:^5.1.0" "@rollup/plugin-commonjs": "npm:^25.0.7" "@rollup/plugin-dynamic-import-vars": "npm:^2.1.2"