Skip to content

Commit 3609bd9

Browse files
committed
Add jscodeshift back
1 parent 946afff commit 3609bd9

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

packages/angular-html-parser/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@
1919
"license": "MIT",
2020
"scripts": {
2121
"prepublish": "yarn run build",
22-
"build": "yarn clean && yarn build-lib",
22+
"build": "yarn clean && yarn build-lib && yarn codemod",
2323
"clean": "del-cli ./lib",
2424
"build-lib": "tsc -p tsconfig.build.json",
25+
"codemod": "node ./node_modules/jscodeshift/bin/jscodeshift.js -t postbuild-codemod.ts lib --extensions=js,ts --parser=ts",
2526
"test": "ts-node --project tsconfig.test.json -r tsconfig-paths/register node_modules/jasmine/bin/jasmine.js ../compiler/test/ml_parser/*_spec.ts ./test/*_spec.ts",
2627
"release": "standard-version"
2728
},
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import {API, FileInfo} from 'jscodeshift';
2+
3+
export default function transformer(file: FileInfo, api: API) {
4+
const j = api.jscodeshift;
5+
6+
const ast = j(file.source);
7+
8+
ast.find(j.ImportDeclaration).forEach(({node}) => {
9+
const source = node.source.value as string;
10+
if (!source.endsWith('.js')) {
11+
node.source.value = source + '.js';
12+
}
13+
});
14+
15+
ast.find(j.TSTypeAliasDeclaration).forEach(({node}) => {
16+
if (node.id.name === 'Node' && node.typeAnnotation.type === 'TSUnionType') {
17+
node.typeAnnotation.types = node.typeAnnotation.types.filter(
18+
(type) =>
19+
type.type === 'TSTypeReference' &&
20+
type.typeName.type === 'Identifier' &&
21+
type.typeName.name !== 'Expansion' &&
22+
type.typeName.name !== 'ExpansionCase'
23+
);
24+
}
25+
});
26+
27+
return ast.toSource();
28+
}

0 commit comments

Comments
 (0)