Skip to content

Commit

Permalink
fix(github-actions): improve error logging and fix ESM node resolution
Browse files Browse the repository at this point in the history
We recently prioritized `module` over `main` but this results in browser
code being prioritized sometimes. We revert that change and keep the
original/default ESBuild main field order.

This unveils an issue with `jsonc-parser` though- which ships an UMD
file for `main` that cannot be bundled. We can work around this by
processing `jsonc-parser`'s ESM output directly and then using that
instead of leaving resolution to ESBuild for this package.

There is an issue for this being tracked: microsoft/node-jsonc-parser#57
  • Loading branch information
devversion committed Oct 21, 2022
1 parent a67b584 commit 5905c01
Show file tree
Hide file tree
Showing 22 changed files with 120,369 additions and 110,196 deletions.
23,016 changes: 12,277 additions & 10,739 deletions .github/local-actions/changelog/main.js

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion bazel/esbuild/index.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ def esbuild_esm_bundle(name, **kwargs):

args = dict(
resolveExtensions = [".mjs", ".js", ".json"],
mainFields = ["module", "main"],
outExtension = {".js": ".mjs"},
# Workaround for: https://github.com/evanw/esbuild/issues/1921.
banner = {
Expand Down
2 changes: 1 addition & 1 deletion github-actions/commit-message-based-labels/lib/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class CommitMessageBasedLabelManager {
// to prevent the action from actually running in a fork of a repository with this action set up.
if (context.repo.owner === 'angular') {
CommitMessageBasedLabelManager.run().catch((e: Error) => {
core.error(e);
console.error(e);
core.setFailed(e.message);
});
} else {
Expand Down
30,320 changes: 15,890 additions & 14,430 deletions github-actions/commit-message-based-labels/main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion github-actions/create-pr-for-changes/lib/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ async function main(): Promise<void> {
}
} catch (err: any) {
core.setOutput('result', ActionResult.failed);
core.error(err);
console.error(err);
core.setFailed(err.message);
}
}
Expand Down
13,598 changes: 6,143 additions & 7,455 deletions github-actions/create-pr-for-changes/main.js

Large diffs are not rendered by default.

22,315 changes: 11,917 additions & 10,398 deletions github-actions/feature-request/main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion github-actions/google-internal-tests/lib/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,6 @@ async function findExistingTestStatus(
}

main().catch((e: Error) => {
core.error(e);
console.error(e);
core.setFailed(e.message);
});
14,509 changes: 6,929 additions & 7,580 deletions github-actions/google-internal-tests/main.js

Large diffs are not rendered by default.

22,179 changes: 11,849 additions & 10,330 deletions github-actions/labels-sync/main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion github-actions/lock-closed/lib/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ async function runLockClosedAction(github: Octokit): Promise<void> {
// Runs triggered via 'workflow_dispatch' are also allowed to run.
if (context.repo.owner === 'angular' || context.eventName === 'workflow_dispatch') {
main().catch((e: Error) => {
core.error(e);
console.error(e);
core.setFailed(e.message);
});
} else {
Expand Down
22,177 changes: 11,848 additions & 10,329 deletions github-actions/lock-closed/main.js

Large diffs are not rendered by default.

22,245 changes: 11,882 additions & 10,363 deletions github-actions/org-file-sync/main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion github-actions/post-approval-changes/lib/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ async function runPostApprovalChangesAction(client: Octokit): Promise<void> {
// Runs triggered via 'workflow_dispatch' are also allowed to run.
if (context.repo.owner === 'angular') {
main().catch((e: Error) => {
core.error(e);
console.error(e);
core.setFailed(e.message);
});
} else {
Expand Down
22,221 changes: 11,870 additions & 10,351 deletions github-actions/post-approval-changes/main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion github-actions/slash-commands/lib/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ async function runSlashCommandsAction(
// to prevent the action from actually running in a fork of a repository with this action set up.
if (context.repo.owner === 'angular') {
main().catch((e: Error) => {
core.error(e);
console.error(e);
core.setFailed(e.message);
});
} else {
Expand Down
37,942 changes: 19,730 additions & 18,212 deletions github-actions/slash-commands/main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion ng-dev/caretaker/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ ts_library(
"//ng-dev:__subpackages__",
],
deps = [
"//tools/esm-interop:jsonc-parser",
"@npm//@types/minimatch",
"@npm//@types/node",
"@npm//jsonc-parser",
"@npm//minimatch",
],
)
Expand Down
2 changes: 1 addition & 1 deletion ng-dev/caretaker/g3-sync-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import minimatch from 'minimatch';
import fs from 'fs';
import * as jsonc from 'jsonc-parser';
import * as jsonc from '../../tools/esm-interop/jsonc-parser.js';

/** Configuration describing how files are synced into Google. */
export interface GoogleSyncConfig {
Expand Down
4 changes: 4 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/**
* @fileoverview Description of this file.
*/
console.error(crypto);
21 changes: 21 additions & 0 deletions tools/esm-interop/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
load("@build_bazel_rules_nodejs//:index.bzl", "js_library")
load("//tools:defaults.bzl", "esbuild")

package(default_visibility = [
"//github-actions:__subpackages__",
"//ng-dev:__subpackages__",
])

esbuild(
name = "jsonc_parser_bundle",
entry_point = "@npm//:node_modules/jsonc-parser/lib/esm/main.js",
output = "jsonc-parser.js",
deps = ["@npm//jsonc-parser"],
)

# Workaround for: https://github.com/microsoft/node-jsonc-parser/issues/57.
js_library(
name = "jsonc-parser",
srcs = ["jsonc-parser.d.ts"],
deps = [":jsonc_parser_bundle"],
)
1 change: 1 addition & 0 deletions tools/esm-interop/jsonc-parser.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from 'jsonc-parser';

0 comments on commit 5905c01

Please sign in to comment.