Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions packages/compiler-cli/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package(default_visibility = ["//visibility:public"])
PUBLIC_TARGETS = [
":compiler-cli",
"//packages/compiler-cli/private",
"//packages/compiler-cli/ngcc",
"//packages/compiler-cli/linker",
"//packages/compiler-cli/linker/babel",
]
Expand All @@ -22,6 +23,7 @@ esbuild(
entry_points = [
":index.ts",
"//packages/compiler-cli:src/bin/ngc.ts",
"//packages/compiler-cli/ngcc:index.ts",
"//packages/compiler-cli:src/bin/ng_xi18n.ts",
"//packages/compiler-cli/linker:index.ts",
"//packages/compiler-cli/linker/babel:index.ts",
Expand Down
12 changes: 12 additions & 0 deletions packages/compiler-cli/ngcc/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
load("//tools:defaults.bzl", "ts_library")

package(default_visibility = ["//visibility:public"])

ts_library(
name = "ngcc",
srcs = ["index.ts"],
tsconfig = "//packages/compiler-cli:tsconfig",
deps = [
"@npm//@types/node",
],
)
59 changes: 59 additions & 0 deletions packages/compiler-cli/ngcc/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/usr/bin/env node
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/

// https://github.com/chalk/chalk/blob/a370f468a43999e4397094ff5c3d17aadcc4860e/source/utilities.js#L21
function stringEncaseCRLFWithFirstIndex(
value: string, prefix: string, postfix: string, index: number): string {
let endIndex = 0;
let returnValue = '';

do {
const gotCR = value[index - 1] === '\r';
returnValue += value.substring(endIndex, gotCR ? index - 1 : index) + prefix +
(gotCR ? '\r\n' : '\n') + postfix;
endIndex = index + 1;
index = value.indexOf('\n', endIndex);
} while (index !== -1);

returnValue += value.substring(endIndex);
return returnValue;
}

// adapted from
// https://github.com/chalk/chalk/blob/a370f468a43999e4397094ff5c3d17aadcc4860e/source/index.js#L194
function styleMessage(message: string): string {
// red + bold
const open = '\x1b[31m\x1b[1m';
const close = '\x1b[22m\x1b[39m';

let styledMessage = message;
const lfIndex = styledMessage.indexOf('\n');
if (lfIndex !== -1) {
styledMessage = stringEncaseCRLFWithFirstIndex(styledMessage, close, open, lfIndex);
}

return open + styledMessage + close;
}

const warningMsg = `

==========================================

ALERT: As of Angular 16, "ngcc" is no longer required and not invoked during CLI builds. You are seeing this message because the current operation invoked the "ngcc" command directly. This "ngcc" invocation can be safely removed.

A common reason for this is invoking "ngcc" from a "postinstall" hook in package.json.

In Angular 17, this command will be removed. Remove this and any other invocations to prevent errors in later versions.

==========================================

`;

console.warn(styleMessage(warningMsg));
process.exit(0);
1 change: 1 addition & 0 deletions packages/compiler-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"description": "Angular - the compiler CLI for Node.js",
"typings": "index.d.ts",
"bin": {
"ngcc": "./bundles/ngcc/index.js",
"ngc": "./bundles/src/bin/ngc.js",
"ng-xi18n": "./bundles/src/bin/ng_xi18n.js"
},
Expand Down