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

fix: runtime errors for ESM distributions #2060

Merged
merged 13 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
ci: added runtime validation for package distribution entrypoints
  • Loading branch information
petertonysmith94 committed Apr 15, 2024
commit 7d135c7c572ccd8217e19d9c71d0d0c1249065a5
3 changes: 3 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ jobs:
- name: Verify package.json integrity
run: pnpm lint:package-jsons

- name: Verify package exports integrity
run: pnpm verify:package-exports

- name: Forc Format Check
run: pnpm forc:check

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"lint:fix": "pnpm lint:check --fix",
"lint:md-links": "tsx ./scripts/lint-md-links",
"lint:package-jsons": "tsx ./scripts/lint-package-jsons",
"verify:package-exports": "tsx ./scripts/verify-package-exports",
"prettier:check": "prettier --check packages",
"prettier:format": "prettier --write packages",
"changeset:publish": "tsx ./scripts/changeset/changeset-publish",
Expand Down
50 changes: 50 additions & 0 deletions scripts/verify-package-exports.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { execSync } from 'child_process';
import { log, error } from 'console';
import { readFileSync } from 'fs';
import { globSync } from 'glob';
import { dirname, join } from 'path';

interface PackageJson {
name: string;
private: boolean;
exports: Record<string, {
require: string;
import: string;
}>
}

/**
* Get only the package's with exports
*/
const packagesWithExports = globSync(`{packages,apps}/*/package.json`)
.map((path) => {
const pkgJson = JSON.parse(readFileSync(path, 'utf-8')) as PackageJson;
return { ...pkgJson, path: dirname(path) };
})
.filter((json) => !json.private && json.exports)

let errorCode = 0;

/**
* 1). Runtime checks on package exports
*/
Object
.values(packagesWithExports)
.flatMap(pkg => Object
.values(pkg.exports)
.flatMap((e) => [e.require, e.import])
.map((entrypoint) => join(pkg.path, entrypoint))
)
.forEach(entrypoint => {
try {
execSync(`node ${entrypoint}`)
arboleya marked this conversation as resolved.
Show resolved Hide resolved
log(`Success | ${entrypoint}`)
} catch (e) {
error(`Error | Package export types`);
error(entrypoint)
error(e.toString());
errorCode = 1;
}
})

process.exit(errorCode);