Skip to content

Commit 58ddeeb

Browse files
Merge branch '18.1.x' into ganastasov/fix-14262-18.1.x
2 parents 03ef7ae + 5e3f544 commit 58ddeeb

File tree

5 files changed

+60
-14
lines changed

5 files changed

+60
-14
lines changed

.vscode/launch.json

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,13 @@
2727
// "cwd": "<absolute directory of the project, having an old version of igniteui-angular, on which the migrations are applied>",
2828
"cwd": "C:\\Users\\User\\Desktop\\ng_proj\\test_migrations",
2929
"args": [
30-
"-r",
31-
32-
// you need to install ts-node for the test project
33-
"ts-node/register",
34-
3530
// "<path/to/ng>", "g",
3631
"${env:AppData}/npm/node_modules/@angular/cli/bin/ng", "g",
3732

38-
// "<../../relative/path/from/cwd/to>/igniteui-angular/projects/igniteui-angular/migrations/migration-collection.json:migration-<number>
39-
"../../../../../work/git/igniteui-angular/projects/igniteui-angular/migrations/migration-collection.json:migration-24"
33+
// "<../../relative/path/from/cwd/to>/igniteui-angular/dist/igniteui-angular/migrations/migration-collection.json:migration-<number>
34+
"../../../../../work/git/igniteui-angular/dist/igniteui-angular/migrations/migration-collection.json:migration-23"
4035
],
41-
"env": {
42-
"TS_NODE_PROJECT": "${workspaceFolder}/projects/igniteui-angular/migrations/tsconfig.json"
43-
}
36+
"preLaunchTask": "buildMigrations"
4437
},
4538
{
4639
"name": "Run schematics",

.vscode/tasks.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"version": "2.0.0",
3+
"tasks": [
4+
{
5+
"type": "npm",
6+
"script": "build:schematics",
7+
"problemMatcher": [],
8+
"label": "buildSchematics",
9+
"detail": "Build schematics"
10+
},
11+
{
12+
"type": "npm",
13+
"script": "build:migrations -- --sourceMap",
14+
"dependsOn": [
15+
"buildSchematics"
16+
],
17+
"problemMatcher": [],
18+
"label": "buildMigrationsSourceMap",
19+
"detail": "Build migrations with sourceMap for debugging"
20+
},
21+
{
22+
"type": "shell",
23+
"command": "node ./scripts/migrations-sourcemap-shift.mjs",
24+
"dependsOn": [
25+
"buildMigrationsSourceMap"
26+
],
27+
"problemMatcher": [],
28+
"label": "buildMigrations",
29+
"detail": "Build migrations with sourceMap for debugging"
30+
},
31+
]
32+
}

projects/igniteui-angular/migrations/common/ServerHost.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { Tree } from '@angular-devkit/schematics';
22
import * as pathFs from 'path';
33
import * as ts from 'typescript/lib/tsserverlibrary';
44
import { CUSTOM_TS_PLUGIN_NAME, CUSTOM_TS_PLUGIN_PATH } from './tsUtils';
5+
import { createRequire } from 'module';
56

67
/**
78
* Language server host is responsible for **most** of the FS operations / checks
@@ -11,6 +12,8 @@ export class ServerHost implements ts.server.ServerHost {
1112
public readonly args: string[];
1213
public readonly newLine: string;
1314
public readonly useCaseSensitiveFileNames: boolean;
15+
/** Cached because Angular schematics encapsulation's customRequire doesn't provide `resolve` */
16+
private nativeRequire = createRequire(__filename);
1417

1518
constructor(private host: Tree) {
1619
this.args = ts.sys.args;
@@ -126,7 +129,7 @@ export class ServerHost implements ts.server.ServerHost {
126129
moduleName = CUSTOM_TS_PLUGIN_PATH;
127130
paths.push(__dirname);
128131
}
129-
const modulePath = require.resolve(moduleName, { paths });
132+
const modulePath = this.nativeRequire.resolve(moduleName, { paths });
130133
return {
131134
module: require(modulePath),
132135
error: undefined,

projects/igniteui-angular/migrations/common/UpdateChanges.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,7 @@ export class UpdateChanges {
682682
}
683683

684684
// attempt to find a main tsconfig from workspace:
685-
const wsProject = this.workspace.projects[0];
685+
const wsProject = Object.values(this.workspace.projects)[0];
686686
// technically could be per-project, but assuming there's at least one main tsconfig for IDE support
687687
const projectConfig = wsProject.architect?.build?.options['tsConfig'];
688688

@@ -847,8 +847,8 @@ export class UpdateChanges {
847847
for (const key of projectKeys) {
848848
const wsProject = this.workspace.projects[key];
849849
// intentionally compare against string values of the enum to avoid hard import
850-
if (wsProject.projectType == "application" && wsProject.architect?.build?.options['main']) {
851-
return wsProject.architect.build.options['main'];
850+
if (wsProject.projectType == "application" && wsProject.architect?.build?.options) {
851+
return wsProject.architect.build.options['browser'] || wsProject.architect.build.options['main'];
852852
} else if (wsProject.projectType == "library") {
853853
// TODO: attempt to resolve from project ng-package.json or tsConfig
854854
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { globby } from 'globby';
2+
import { readFileSync, writeFileSync } from 'fs';
3+
4+
/**
5+
* Small patch for debugging compiled migrations that get wrapped with extra lines for encapsulation:
6+
* https://github.com/angular/angular-cli/blob/e51b9068763a115fa27d06e2dd7988b34a3f677c/packages/angular/cli/src/command-builder/utilities/schematic-engine-host.ts#L213-L215
7+
* Works for the simple "version":3 mappings produced where adding ; at the start shifts the mapped lines (ignores the extra unmapped source)
8+
*/
9+
(async () => {
10+
const paths = await globby('dist/igniteui-angular/migrations/**/*.js.map');
11+
for (const path of paths) {
12+
const extraLine = ';';
13+
const offset = 3;
14+
let content = readFileSync(path, { encoding: 'utf-8' });
15+
content = content.replace(`"mappings":"`, `"mappings":"${extraLine.repeat(offset)}`);
16+
writeFileSync(path, content);
17+
}
18+
})();

0 commit comments

Comments
 (0)