Skip to content

Commit

Permalink
fix(build): clean up exports in the distributed package.json #1616 (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
alecarn committed Jan 30, 2024
1 parent 831f264 commit ecd7013
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 27 deletions.
3 changes: 2 additions & 1 deletion packages/auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"url": "https://github.com/infra-geo-ouverte/igo2-lib/issues"
},
"scripts": {
"build": "ng build auth --configuration production",
"build": "ng build auth --configuration production && npm run clean-exports",
"clean-exports": "ts-node ../../scripts/src/core/clean-exports.ts auth",
"format": "prettier --write ./src/**/*.{ts,js,html,scss,css,json}",
"test": "ng test auth --watch=false",
"watch": "ng build auth --watch"
Expand Down
3 changes: 2 additions & 1 deletion packages/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"url": "https://github.com/infra-geo-ouverte/igo2-lib/issues"
},
"scripts": {
"build": "ng build common --configuration production",
"build": "ng build common --configuration production && npm run clean-exports",
"clean-exports": "ts-node ../../scripts/src/core/clean-exports.ts common",
"format": "prettier --write ./src/**/*.{ts,js,html,scss,css,json}",
"postbuild": "ts-node ../../scripts/src/common/postbuild-common.ts",
"test": "ng test common --watch=false",
Expand Down
3 changes: 2 additions & 1 deletion packages/context/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"url": "https://github.com/infra-geo-ouverte/igo2-lib/issues"
},
"scripts": {
"build": "ng build context --configuration production",
"build": "ng build context --configuration production && npm run clean-exports",
"clean-exports": "ts-node ../../scripts/src/core/clean-exports.ts context",
"format": "prettier --write ./src/**/*.{ts,js,html,scss,css,json}",
"test": "ng test context --watch=false",
"watch": "ng build context --watch"
Expand Down
3 changes: 2 additions & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
},
"scripts": {
"prestart": "npm run postbuild",
"build": "ng build core --configuration production",
"build": "ng build core --configuration production && npm run clean-exports",
"clean-exports": "ts-node ../../scripts/src/core/clean-exports.ts core",
"format": "prettier --write ./src/**/*.{ts,js,html,scss,css,json}",
"postbuild": "ts-node ../../scripts/src/core/postbuild-core.ts",
"test": "ng test core --watch=false",
Expand Down
3 changes: 2 additions & 1 deletion packages/geo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"url": "https://github.com/infra-geo-ouverte/igo2-lib/issues"
},
"scripts": {
"build": "ng build geo --configuration production",
"build": "ng build geo --configuration production && npm run clean-exports",
"clean-exports": "ts-node ../../scripts/src/core/clean-exports.ts geo",
"format": "prettier --write ./src/**/*.{ts,js,html,scss,css,json}",
"postbuild": "ts-node ../../scripts/src/geo/postbuild-geo.ts",
"test": "ng test geo --watch=false",
Expand Down
3 changes: 2 additions & 1 deletion packages/integration/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"url": "https://github.com/infra-geo-ouverte/igo2-lib/issues"
},
"scripts": {
"build": "ng build integration --configuration production",
"build": "ng build integration --configuration production && npm run clean-exports",
"clean-exports": "ts-node ../../scripts/src/core/clean-exports.ts integration",
"format": "prettier --write ./src/**/*.{ts,js,html,scss,css,json}",
"test": "",
"watch": "ng build integration --watch"
Expand Down
3 changes: 2 additions & 1 deletion packages/utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"url": "https://github.com/infra-geo-ouverte/igo2-lib/issues"
},
"scripts": {
"build": "ng build utils --configuration production",
"build": "ng build utils --configuration production && npm run clean-exports",
"clean-exports": "ts-node ../../scripts/src/core/clean-exports.ts utils",
"format": "prettier --write ./src/**/*.{ts,js,html,scss,css,json}",
"publish": "npm publish ../../dist/utils",
"test": "ng test utils --watch=false",
Expand Down
22 changes: 2 additions & 20 deletions scripts/src/build-library.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { rm } from 'fs/promises';
import { resolve } from 'path';

import { PACKAGES_RELATIONS, waitOnPackageRelations } from './config/packages';
import { PATHS, getPackageJson } from './config/paths';
import { pathExist, writeFile2 } from './utils/file-system.utils';
import { PATHS } from './config/paths';
import { pathExist } from './utils/file-system.utils';
import * as log from './utils/log';
import { getDuration } from './utils/performance.utils';

Expand Down Expand Up @@ -34,23 +33,6 @@ const baseCmdName = 'Build all library';

await Promise.all(promises);

// Remove any Typescript references for Distribution
await removePublicApiExports();

const duration = getDuration(startTime);
log.info(`${baseCmdName} in ${duration}`);
})();

async function removePublicApiExports() {
for (const [packageName] of PACKAGES_RELATIONS) {
const packageJSON = getPackageJson('dist', packageName);
const rootExports = packageJSON.exports['.'];
if (rootExports && typeof rootExports === 'object' && rootExports?.import) {
delete rootExports?.import;
}
await writeFile2(
resolve(PATHS.dist, packageName, 'package.json'),
packageJSON
);
}
}
26 changes: 26 additions & 0 deletions scripts/src/core/clean-exports.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { resolve } from 'path';

import { PATHS, getPackageJson } from '../config/paths';
import { writeFile2 } from '../utils/file-system.utils';
import * as log from '../utils/log';
import { getDuration } from '../utils/performance.utils';

const baseCmdName = 'Clean exports';

(async () => {
const startTime = performance.now();
const [_nodePath, _scriptPath, name] = process.argv;

log.startMsg(`${baseCmdName} for ${name}`);

// Remove any Typescript references for Distribution
const packageJSON = getPackageJson('dist', name);
const rootExports = packageJSON.exports['.'];
if (rootExports && typeof rootExports === 'object' && rootExports?.import) {
delete rootExports?.import;
}
await writeFile2(resolve(PATHS.dist, name, 'package.json'), packageJSON);

const duration = getDuration(startTime);
log.info(`${baseCmdName} in ${duration}`);
})();

0 comments on commit ecd7013

Please sign in to comment.