Skip to content

Commit

Permalink
Chore(internal): Review repo setup to consider not emitting TS declar…
Browse files Browse the repository at this point in the history
…ations
  • Loading branch information
SBoudrias committed Jul 1, 2024
1 parent e2dc532 commit e686841
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions tools/setup-packages.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -58,35 +58,36 @@ paths.forEach(async (pkgPath) => {

if (isTS) {
const tsconfig = await readJSONFile(tsconfigPath);
const emitDeclaration = tsconfig?.compilerOptions?.declaration !== false;

delete pkg.type;
pkg.scripts = pkg.scripts ?? {};
pkg.files = ['dist/**/*'];

// If the package supports Typescript, then apply the configs.
pkg.exports = {
'.': {
import: {
types: './dist/esm/types/index.d.mts',
types: emitDeclaration ? './dist/esm/types/index.d.mts' : undefined,
default: './dist/esm/index.mjs',
},
require: {
types: './dist/cjs/types/index.d.ts',
types: emitDeclaration ? './dist/cjs/types/index.d.ts' : undefined,
default: './dist/cjs/index.js',
},
},
};

pkg.main = pkg.exports['.'].require.default;
pkg.typings = pkg.exports['.'].require.types;
pkg.files = ['dist/**/*'];
pkg.typings = emitDeclaration ? pkg.exports['.'].require.types : undefined;

pkg.scripts = {
tsc: 'yarn run tsc:esm && yarn run tsc:cjs',
'tsc:esm': 'rm -rf dist/esm && tsc -p ./tsconfig.json',
'tsc:cjs':
'rm -rf dist/cjs && tsc -p ./tsconfig.cjs.json && node ../../tools/fix-ext.mjs',
dev: 'tsc -p ./tsconfig.json --watch',
attw: 'attw --pack',
attw: emitDeclaration ? 'attw --pack' : undefined,
};

// Set ESM tsconfig
Expand All @@ -101,7 +102,7 @@ paths.forEach(async (pkgPath) => {
module: 'NodeNext',
moduleResolution: 'nodenext',
outDir: 'dist/esm',
declarationDir: 'dist/esm/types',
declarationDir: emitDeclaration ? 'dist/esm/types' : undefined,
},
};

Expand All @@ -114,7 +115,7 @@ paths.forEach(async (pkgPath) => {
module: 'commonjs',
moduleResolution: 'node10',
outDir: 'dist/cjs',
declarationDir: 'dist/cjs/types',
declarationDir: emitDeclaration ? 'dist/cjs/types' : undefined,
},
};

Expand Down

0 comments on commit e686841

Please sign in to comment.