From 6f16a7868ba235fa2c8a16cea6acc45e8eac6e36 Mon Sep 17 00:00:00 2001 From: Anh Pham <anh.pham@cm.com> Date: Tue, 30 Jan 2024 06:36:03 +0100 Subject: [PATCH] feat: support signal input in 17.1 --- package.json | 3 +- scripts/prebuild.js | 65 +++++------------------------- src/transformers/downlevel-ctor.ts | 15 ++++++- 3 files changed, 26 insertions(+), 57 deletions(-) diff --git a/package.json b/package.json index 987fde6281..92ffe27fa3 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,8 @@ "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 1", "prepublishOnly": "pinst --disable", "postpublish": "pinst --enable", - "update-e2e": "node scripts/update-e2e.js" + "update-e2e": "node scripts/update-e2e.js", + "build-ng-source": "node scripts/prebuild.js" }, "dependencies": { "bs-logger": "^0.2.6", diff --git a/scripts/prebuild.js b/scripts/prebuild.js index 8f71bfe312..196cec77fb 100644 --- a/scripts/prebuild.js +++ b/scripts/prebuild.js @@ -1,55 +1,10 @@ -const chalk = require('chalk'); -const execa = require('execa'); - -const buildDir = 'build'; -const ngTransformerPath = `./src/transformers/downlevel_decorators_transform`; -const bazelFileGlob = 'src/**/BUILD.bazel'; -const ngTestFolder = 'src/ngtsc/reflection/test'; -const ngTransformerURL = - 'https://github.com/angular/angular/blob/15.0.4/packages/compiler-cli/src/transformers/downlevel_decorators_transform'; -const ngReflectionURL = 'https://github.com/angular/angular/blob/15.0.4/packages/compiler-cli/src/ngtsc/reflection'; -const tsCompatUrl = 'https://github.com/angular/angular/blob/15.0.4/packages/compiler-cli/src/ngtsc/ts_compatibility'; -const transformersFolder = './src/transformers'; -const ngtscFolder = './src/ngtsc'; - -process.stdout.write(chalk.green(' \u2022 ') + 'clean up ' + chalk.blue(buildDir) + '\n'); - -execa.sync('yarn', ['rimraf', buildDir]); - -process.stdout.write( - chalk.green(' \u2022 ') + - 'clean up previously downloaded assets' + - chalk.blue(`${ngTransformerPath}, ${ngtscFolder}`) + - '\n' -); - -execa.sync('yarn', ['rimraf', ngTransformerPath, ngtscFolder]); - -process.stdout.write( - chalk.green(' \u2022 ') + - `downloading Angular Downlevel Decorator Transformer from ${ngTransformerURL}` + - chalk.green(' \u21D2 ') + - transformersFolder + - '\n' -); - -execa.sync('yarn', ['fetcher', `--url=${ngTransformerURL}`, `--out=${transformersFolder}`]); - -process.stdout.write( - chalk.green(' \u2022 ') + - `downloading dependencies for Angular Downlevel Decorator Transformer from ${[ngReflectionURL, tsCompatUrl]}` + - chalk.green(' \u21D2 ') + - ngtscFolder + - '\n' -); - -execa.sync('yarn', ['fetcher', `--url=${ngReflectionURL}`, `--out=${ngtscFolder}`]); -execa.sync('yarn', ['fetcher', `--url=${tsCompatUrl}`, `--out=${ngtscFolder}`]); - -process.stdout.write(chalk.green(' \u2022 ') + 'clean up Bazel files ' + chalk.blue(bazelFileGlob) + '\n'); - -execa.sync('yarn', ['rimraf', bazelFileGlob]); - -process.stdout.write(chalk.green(' \u2022 ') + 'clean up Angular test files ' + chalk.blue(ngTestFolder) + '\n'); - -execa.sync('yarn', ['rimraf', ngTestFolder]); +const { buildSync } = require('esbuild'); + +buildSync({ + entryPoints: ['src/transformers/downlevel-ctor.ts'], + outdir: 'build', + external: ['esbuild', 'ts-jest', 'typescript'], + platform: 'node', + target: 'node16', + bundle: true, +}); diff --git a/src/transformers/downlevel-ctor.ts b/src/transformers/downlevel-ctor.ts index 04810b85c9..e039d17602 100644 --- a/src/transformers/downlevel-ctor.ts +++ b/src/transformers/downlevel-ctor.ts @@ -1,3 +1,4 @@ +import { getInputSignalsMetadataTransform } from '@angular/compiler-cli/src/transformers/jit_transforms'; import type ts from 'typescript'; import { TypeScriptReflectionHost } from '../ngtsc/reflection'; @@ -7,6 +8,18 @@ import { getDownlevelDecoratorsTransform } from './downlevel_decorators_transfor export const constructorParametersDownlevelTransform = (program: ts.Program): ts.TransformerFactory<ts.SourceFile> => { const typeChecker = program.getTypeChecker(); const reflectionHost = new TypeScriptReflectionHost(typeChecker); + const inputSignalMetadataTransform = getInputSignalsMetadataTransform(reflectionHost, false); - return getDownlevelDecoratorsTransform(typeChecker, reflectionHost, [], false, false, true); + return (ctx) => { + return (sourceFile) => { + if (inputSignalMetadataTransform) { + sourceFile = inputSignalMetadataTransform(ctx)(sourceFile); + } + sourceFile = getDownlevelDecoratorsTransform(typeChecker, reflectionHost, [], false, false, true)(ctx)( + sourceFile, + ); + + return sourceFile; + }; + }; };