Skip to content

Commit b09cbfb

Browse files
authored
Merge pull request #13 from nestjs-addons/build_file
build(platform): add build file and fix linting
2 parents 200334f + a8bae21 commit b09cbfb

File tree

6 files changed

+528
-110
lines changed

6 files changed

+528
-110
lines changed

.eslintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"error",
2424
{
2525
"enforceBuildableLibDependency": true,
26-
"allow": [],
26+
"allow": ["playground"],
2727
"depConstraints": [
2828
{ "sourceTag": "*", "onlyDependOnLibsWithTags": ["*"] }
2929
]

.github/workflows/build.yml

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
name: CI Checks
2+
on:
3+
pull_request:
4+
branches: [master]
5+
push:
6+
branches: [master]
7+
8+
jobs:
9+
setup:
10+
runs-on: ${{ matrix.os }}
11+
strategy:
12+
matrix:
13+
os: [ubuntu-latest, windows-latest]
14+
node-version: [12.x]
15+
steps:
16+
- name: Use Node.js ${{ matrix.node-version }}
17+
uses: actions/setup-node@v1
18+
with:
19+
node-version: ${{ matrix.node-version }}
20+
- uses: actions/checkout@v2
21+
with:
22+
fetch-depth: 3
23+
- name: Get origin master
24+
run: |
25+
git fetch --no-tags --prune --depth=1 origin +refs/heads/master:refs/remotes/origin/master
26+
- uses: actions/cache@v1
27+
id: workspace-cache
28+
with:
29+
path: node_modules
30+
key: ${{ runner.os }}-${{ matrix.node-version }}-workspace-${{ hashFiles('**/yarn.lock') }}
31+
restore-keys: |
32+
${{ runner.os }}-${{ matrix.node-version }}-workspace-
33+
- name: Install Dependencies
34+
run: yarn install --frozen-lockfile
35+
lint:
36+
runs-on: ${{ matrix.os }}
37+
38+
needs: [setup]
39+
strategy:
40+
matrix:
41+
os: [ubuntu-latest, windows-latest]
42+
node-version: [12.x]
43+
44+
steps:
45+
- name: Use Node.js ${{ matrix.node-version }}
46+
uses: actions/setup-node@v1
47+
with:
48+
node-version: ${{ matrix.node-version }}
49+
- uses: actions/checkout@v2
50+
with:
51+
fetch-depth: 3
52+
- name: Get origin master
53+
if: github.event_name == 'pull_request'
54+
run: |
55+
git fetch --no-tags --prune --depth=1 origin +refs/heads/master:refs/remotes/origin/master
56+
- uses: actions/cache@v1
57+
id: workspace-cache
58+
with:
59+
path: node_modules
60+
key: ${{ runner.os }}-${{ matrix.node-version }}-workspace-${{ hashFiles('**/yarn.lock') }}
61+
restore-keys: |
62+
${{ runner.os }}-${{ matrix.node-version }}-workspace-
63+
- name: Run On Master (Linux)
64+
if: github.event_name == 'push' && runner.os == 'Linux'
65+
run: yarn affected:lint --base=$GITHUB_REF~1 --head=$GITHUB_SHA --parallel
66+
- name: Run On Master (Windows)
67+
if: github.event_name == 'push' && runner.os == 'Windows'
68+
run: yarn affected:lint --base=${env:GITHUB_REF}~1 --head=${env:GITHUB_SHA} --parallel
69+
- name: Run on PR
70+
if: github.event_name == 'pull_request'
71+
run: yarn affected:lint --base=origin/master --head=HEAD --parallel
72+
73+
build:
74+
runs-on: ${{ matrix.os }}
75+
76+
needs: [setup]
77+
78+
strategy:
79+
matrix:
80+
os: [ubuntu-latest, windows-latest]
81+
node-version: [12.x]
82+
83+
steps:
84+
- name: Use Node.js ${{ matrix.node-version }}
85+
uses: actions/setup-node@v1
86+
with:
87+
node-version: ${{ matrix.node-version }}
88+
- uses: actions/checkout@v2
89+
with:
90+
fetch-depth: 3
91+
- name: Get origin master
92+
if: github.event_name == 'pull_request'
93+
run: |
94+
git fetch --no-tags --prune --depth=1 origin +refs/heads/master:refs/remotes/origin/master
95+
- uses: actions/cache@v1
96+
id: workspace-cache
97+
with:
98+
path: node_modules
99+
key: ${{ runner.os }}-${{ matrix.node-version }}-workspace-${{ hashFiles('**/yarn.lock') }}
100+
restore-keys: |
101+
${{ runner.os }}-${{ matrix.node-version }}-workspace-
102+
- name: Run On Master (Linux)
103+
if: github.event_name == 'push' && runner.os == 'Linux'
104+
run: yarn affected:build --base=$GITHUB_REF~1 --head=$GITHUB_SHA --parallel
105+
- name: Run On Master (Windows)
106+
if: github.event_name == 'push' && runner.os == 'Windows'
107+
run: yarn affected:build --base=${env:GITHUB_REF}~1 --head=${env:GITHUB_SHA} --parallel
108+
- name: Run on PR
109+
if: github.event_name == 'pull_request'
110+
run: yarn affected:build --base=origin/master --head=HEAD --parallel
111+
112+
test:
113+
runs-on: ${{ matrix.os }}
114+
115+
needs: [setup]
116+
117+
strategy:
118+
matrix:
119+
os: [ubuntu-latest, windows-latest]
120+
node-version: [12.x]
121+
122+
steps:
123+
- name: Use Node.js ${{ matrix.node-version }}
124+
uses: actions/setup-node@v1
125+
with:
126+
node-version: ${{ matrix.node-version }}
127+
- uses: actions/checkout@v2
128+
with:
129+
fetch-depth: 3
130+
- name: Get origin master
131+
if: github.event_name == 'pull_request'
132+
run: |
133+
git fetch --no-tags --prune --depth=1 origin +refs/heads/master:refs/remotes/origin/master
134+
- uses: actions/cache@v1
135+
id: workspace-cache
136+
with:
137+
path: node_modules
138+
key: ${{ runner.os }}-${{ matrix.node-version }}-workspace-${{ hashFiles('**/yarn.lock') }}
139+
restore-keys: |
140+
${{ runner.os }}-${{ matrix.node-version }}-workspace-
141+
- name: Run On Master (Linux)
142+
if: github.event_name == 'push' && runner.os == 'Linux'
143+
run: yarn affected:test --base=$GITHUB_REF~1 --head=$GITHUB_SHA --parallel
144+
- name: Run On Master (Windows)
145+
if: github.event_name == 'push' && runner.os == 'Windows'
146+
run: yarn affected:test --base=${env:GITHUB_REF}~1 --head=${env:GITHUB_SHA} --parallel
147+
- name: Run on PR
148+
if: github.event_name == 'pull_request'
149+
run: yarn affected:test --base=origin/master --head=HEAD --parallel

package.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
"update": "nx migrate latest",
2424
"workspace-schematic": "nx workspace-schematic",
2525
"dep-graph": "nx dep-graph",
26-
"help": "nx help"
26+
"help": "nx help",
27+
"commit": "git-cz"
2728
},
2829
"private": true,
2930
"dependencies": {
@@ -45,6 +46,7 @@
4546
"@types/node": "~8.9.4",
4647
"@typescript-eslint/eslint-plugin": "2.19.2",
4748
"@typescript-eslint/parser": "2.19.2",
49+
"cz-conventional-changelog": "^3.3.0",
4850
"dotenv": "6.2.0",
4951
"eslint": "6.8.0",
5052
"eslint-config-prettier": "6.11.0",
@@ -56,5 +58,10 @@
5658
"ts-node": "~7.0.0",
5759
"tslint": "~6.1.3",
5860
"typescript": "~3.9.3"
61+
},
62+
"config": {
63+
"commitizen": {
64+
"path": "./node_modules/cz-conventional-changelog"
65+
}
5966
}
6067
}

packages/in-memory-db/src/schematics/utils/ast-utils.ts

Lines changed: 86 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,95 @@
66
* Use of this source code is governed by an MIT-style license that can be
77
* found in the LICENSE file at https://angular.io/license
88
*/
9-
import { ImportClause } from 'typescript';
109
import * as ts from 'typescript';
1110
import { Change, InsertChange, NoopChange } from './change';
1211

12+
13+
/**
14+
* Find all nodes from the AST in the subtree of node of SyntaxKind kind.
15+
* @param node
16+
* @param kind
17+
* @param max The maximum number of items to return.
18+
* @return all nodes of kind, or [] if none is found
19+
*/
20+
export function findNodes(
21+
node: ts.Node,
22+
kind: ts.SyntaxKind,
23+
max = Infinity,
24+
): ts.Node[] {
25+
if (!node || max == 0) {
26+
return [];
27+
}
28+
29+
const arr: ts.Node[] = [];
30+
if (node.kind === kind) {
31+
arr.push(node);
32+
max--;
33+
}
34+
if (max > 0) {
35+
for (const child of node.getChildren()) {
36+
findNodes(child, kind, max).forEach((node) => {
37+
if (max > 0) {
38+
arr.push(node);
39+
}
40+
max--;
41+
});
42+
43+
if (max <= 0) {
44+
break;
45+
}
46+
}
47+
}
48+
49+
return arr;
50+
}
51+
52+
/**
53+
* Helper for sorting nodes.
54+
* @return function to sort nodes in increasing order of position in sourceFile
55+
*/
56+
function nodesByPosition(first: ts.Node, second: ts.Node): number {
57+
return first.getStart() - second.getStart();
58+
}
59+
60+
/**
61+
* Insert `toInsert` after the last occurence of `ts.SyntaxKind[nodes[i].kind]`
62+
* or after the last of occurence of `syntaxKind` if the last occurence is a sub child
63+
* of ts.SyntaxKind[nodes[i].kind] and save the changes in file.
64+
*
65+
* @param nodes insert after the last occurence of nodes
66+
* @param toInsert string to insert
67+
* @param file file to insert changes into
68+
* @param fallbackPos position to insert if toInsert happens to be the first occurence
69+
* @param syntaxKind the ts.SyntaxKind of the subchildren to insert after
70+
* @return Change instance
71+
* @throw Error if toInsert is first occurence but fall back is not set
72+
*/
73+
export function insertAfterLastOccurrence(
74+
nodes: ts.Node[],
75+
toInsert: string,
76+
file: string,
77+
fallbackPos: number,
78+
syntaxKind?: ts.SyntaxKind,
79+
): Change {
80+
// sort() has a side effect, so make a copy so that we won't overwrite the parent's object.
81+
let lastItem = [...nodes].sort(nodesByPosition).pop();
82+
if (!lastItem) {
83+
throw new Error();
84+
}
85+
if (syntaxKind) {
86+
lastItem = findNodes(lastItem, syntaxKind).sort(nodesByPosition).pop();
87+
}
88+
if (!lastItem && fallbackPos == undefined) {
89+
throw new Error(
90+
`tried to insert ${toInsert} as first occurence with no fallback position`,
91+
);
92+
}
93+
const lastItemPosition: number = lastItem ? lastItem.getEnd() : fallbackPos;
94+
95+
return new InsertChange(file, lastItemPosition, toInsert);
96+
}
97+
1398
/**
1499
* Add Import `import { symbolName } from fileName` if the import doesn't exit
15100
* already. Assumes fileToEdit can be resolved and accessed.
@@ -129,45 +214,6 @@ export function insertImport(
129214
);
130215
}
131216

132-
/**
133-
* Find all nodes from the AST in the subtree of node of SyntaxKind kind.
134-
* @param node
135-
* @param kind
136-
* @param max The maximum number of items to return.
137-
* @return all nodes of kind, or [] if none is found
138-
*/
139-
export function findNodes(
140-
node: ts.Node,
141-
kind: ts.SyntaxKind,
142-
max = Infinity,
143-
): ts.Node[] {
144-
if (!node || max == 0) {
145-
return [];
146-
}
147-
148-
const arr: ts.Node[] = [];
149-
if (node.kind === kind) {
150-
arr.push(node);
151-
max--;
152-
}
153-
if (max > 0) {
154-
for (const child of node.getChildren()) {
155-
findNodes(child, kind, max).forEach((node) => {
156-
if (max > 0) {
157-
arr.push(node);
158-
}
159-
max--;
160-
});
161-
162-
if (max <= 0) {
163-
break;
164-
}
165-
}
166-
}
167-
168-
return arr;
169-
}
170-
171217
/**
172218
* Get all the nodes from a source.
173219
* @param sourceFile The source file object.
@@ -209,52 +255,6 @@ export function findNode(
209255
return foundNode;
210256
}
211257

212-
/**
213-
* Helper for sorting nodes.
214-
* @return function to sort nodes in increasing order of position in sourceFile
215-
*/
216-
function nodesByPosition(first: ts.Node, second: ts.Node): number {
217-
return first.getStart() - second.getStart();
218-
}
219-
220-
/**
221-
* Insert `toInsert` after the last occurence of `ts.SyntaxKind[nodes[i].kind]`
222-
* or after the last of occurence of `syntaxKind` if the last occurence is a sub child
223-
* of ts.SyntaxKind[nodes[i].kind] and save the changes in file.
224-
*
225-
* @param nodes insert after the last occurence of nodes
226-
* @param toInsert string to insert
227-
* @param file file to insert changes into
228-
* @param fallbackPos position to insert if toInsert happens to be the first occurence
229-
* @param syntaxKind the ts.SyntaxKind of the subchildren to insert after
230-
* @return Change instance
231-
* @throw Error if toInsert is first occurence but fall back is not set
232-
*/
233-
export function insertAfterLastOccurrence(
234-
nodes: ts.Node[],
235-
toInsert: string,
236-
file: string,
237-
fallbackPos: number,
238-
syntaxKind?: ts.SyntaxKind,
239-
): Change {
240-
// sort() has a side effect, so make a copy so that we won't overwrite the parent's object.
241-
let lastItem = [...nodes].sort(nodesByPosition).pop();
242-
if (!lastItem) {
243-
throw new Error();
244-
}
245-
if (syntaxKind) {
246-
lastItem = findNodes(lastItem, syntaxKind).sort(nodesByPosition).pop();
247-
}
248-
if (!lastItem && fallbackPos == undefined) {
249-
throw new Error(
250-
`tried to insert ${toInsert} as first occurence with no fallback position`,
251-
);
252-
}
253-
const lastItemPosition: number = lastItem ? lastItem.getEnd() : fallbackPos;
254-
255-
return new InsertChange(file, lastItemPosition, toInsert);
256-
}
257-
258258
export function getContentOfKeyLiteral(
259259
_source: ts.SourceFile,
260260
node: ts.Node,

packages/spectator/src/lib/mock.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export function installProtoMethods<T>(
7373
typeof mock[key] === 'undefined'
7474
) {
7575
mock[key] = createSpyFn(key);
76-
} else if (descriptor.get && !mock.hasOwnProperty(key)) {
76+
} else if (descriptor.get && !Object.prototype.hasOwnProperty.call(mock, key)) {
7777
Object.defineProperty(mock, key, {
7878
set: (value) => (mock[`_${key}`] = value),
7979
get: () => mock[`_${key}`],

0 commit comments

Comments
 (0)