Skip to content

Commit

Permalink
feat: support signal input in 17.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Anh Pham committed Jan 30, 2024
1 parent a7b083d commit 6f16a78
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 57 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
65 changes: 10 additions & 55 deletions scripts/prebuild.js
Original file line number Diff line number Diff line change
@@ -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,
});
15 changes: 14 additions & 1 deletion src/transformers/downlevel-ctor.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { getInputSignalsMetadataTransform } from '@angular/compiler-cli/src/transformers/jit_transforms';
import type ts from 'typescript';

import { TypeScriptReflectionHost } from '../ngtsc/reflection';
Expand All @@ -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);

Check failure on line 11 in src/transformers/downlevel-ctor.ts

View workflow job for this annotation

GitHub Actions / lint

Argument of type 'TypeScriptReflectionHost' is not assignable to parameter of type 'ReflectionHost'.

Check failure on line 11 in src/transformers/downlevel-ctor.ts

View workflow job for this annotation

GitHub Actions / test-ubuntu / Node v16.x on ubuntu-latest

Argument of type 'TypeScriptReflectionHost' is not assignable to parameter of type 'ReflectionHost'.

Check failure on line 11 in src/transformers/downlevel-ctor.ts

View workflow job for this annotation

GitHub Actions / test-ubuntu / Node v18.x on ubuntu-latest

Argument of type 'TypeScriptReflectionHost' is not assignable to parameter of type 'ReflectionHost'.

Check failure on line 11 in src/transformers/downlevel-ctor.ts

View workflow job for this annotation

GitHub Actions / test-windows / Node v16.x on windows-latest

Argument of type 'TypeScriptReflectionHost' is not assignable to parameter of type 'ReflectionHost'.

Check failure on line 11 in src/transformers/downlevel-ctor.ts

View workflow job for this annotation

GitHub Actions / test-windows / Node v18.x on windows-latest

Argument of type 'TypeScriptReflectionHost' is not assignable to parameter of type 'ReflectionHost'.

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;
};
};
};

0 comments on commit 6f16a78

Please sign in to comment.