devextreme-schematics 1.12.0 → 1.12.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -14
- package/package.json +2 -2
- package/src/add-app-template/schema.json +1 -1
- package/src/add-layout/files/src/app/app-navigation.ts +3 -1
- package/src/add-layout/index.js +33 -5
- package/src/add-layout/index.js.map +1 -1
- package/src/add-layout/index.ts +42 -6
- package/src/add-layout/index_spec.js +1 -1
- package/src/add-layout/index_spec.ts +1 -1
- package/src/add-sample-views/index_spec.js +2 -1
- package/src/add-sample-views/index_spec.js.map +1 -1
- package/src/add-sample-views/index_spec.ts +3 -1
- package/src/add-view/index_spec.js +2 -1
- package/src/add-view/index_spec.js.map +1 -1
- package/src/add-view/index_spec.ts +3 -1
- package/src/install/schema.json +1 -1
- package/src/migrate-config-components/README.md +14 -27
- package/src/migrate-config-components/index.d.ts +3 -3
- package/src/migrate-config-components/index.js +25 -34
- package/src/migrate-config-components/index.js.map +1 -1
- package/src/migrate-config-components/index.ts +33 -36
- package/src/migrate-config-components/schema.json +4 -3
- package/src/migrate-config-components/template-migrator.js +19 -35
- package/src/migrate-config-components/template-migrator.js.map +1 -1
- package/src/migrate-config-components/template-migrator.ts +19 -32
- package/src/utility/change.js +4 -2
- package/src/utility/change.js.map +1 -1
- package/src/utility/change.ts +7 -2
- package/src/utility/latest-versions.js +2 -2
- package/src/utility/latest-versions.ts +2 -2
- package/src/utility/typescript-resolver.d.ts +12 -0
- package/src/utility/typescript-resolver.js +153 -0
- package/src/utility/typescript-resolver.js.map +1 -0
- package/src/utility/typescript-resolver.ts +144 -0
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { execSync } from 'child_process';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
import * as fs from 'fs';
|
|
4
|
+
|
|
5
|
+
export interface TypeScriptResolutionResult {
|
|
6
|
+
ts: any | null;
|
|
7
|
+
resolutionMethod: 'project' | 'global' | 'temporary' | null;
|
|
8
|
+
errors: string[];
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Resolves TypeScript with a 3-level fallback strategy:
|
|
13
|
+
* 1. Project search - look in the user's project node_modules
|
|
14
|
+
* 2. Global search - look in global node_modules
|
|
15
|
+
* 3. Temporary install - use npx to temporarily install typescript
|
|
16
|
+
*/
|
|
17
|
+
export function resolveTypeScript(): TypeScriptResolutionResult {
|
|
18
|
+
const errors: string[] = [];
|
|
19
|
+
|
|
20
|
+
try {
|
|
21
|
+
const projectTs = tryResolveFromProject();
|
|
22
|
+
if (projectTs) {
|
|
23
|
+
return {
|
|
24
|
+
ts: projectTs,
|
|
25
|
+
resolutionMethod: 'project',
|
|
26
|
+
errors: []
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
} catch (err) {
|
|
30
|
+
errors.push(`Failed to import TypeScript from project: ${err?.message || err}`);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
try {
|
|
34
|
+
const globalTs = tryResolveFromGlobal();
|
|
35
|
+
if (globalTs) {
|
|
36
|
+
return {
|
|
37
|
+
ts: globalTs,
|
|
38
|
+
resolutionMethod: 'global',
|
|
39
|
+
errors: []
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
} catch (err) {
|
|
43
|
+
errors.push(`Failed to import TypeScript from global node_modules: ${err?.message || err}`);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
try {
|
|
47
|
+
const tempTs = tryResolveViaTemporaryInstall();
|
|
48
|
+
if (tempTs) {
|
|
49
|
+
return {
|
|
50
|
+
ts: tempTs,
|
|
51
|
+
resolutionMethod: 'temporary',
|
|
52
|
+
errors: []
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
} catch (err) {
|
|
56
|
+
errors.push(`Failed to import TypeScript from temporary installation (npm cache): ${err?.message || err}`);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return {
|
|
60
|
+
ts: null,
|
|
61
|
+
resolutionMethod: null,
|
|
62
|
+
errors
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function tryResolveFromProject(): any {
|
|
67
|
+
const searchPaths = [
|
|
68
|
+
process.cwd(),
|
|
69
|
+
path.dirname(require.main?.filename || ''),
|
|
70
|
+
];
|
|
71
|
+
|
|
72
|
+
for (const searchPath of searchPaths) {
|
|
73
|
+
try {
|
|
74
|
+
const tsPath = require.resolve('typescript', { paths: [searchPath] });
|
|
75
|
+
// tslint:disable-next-line:no-var-requires
|
|
76
|
+
return require(tsPath);
|
|
77
|
+
} catch {
|
|
78
|
+
// Continue to next path
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function tryResolveFromGlobal(): any {
|
|
86
|
+
try {
|
|
87
|
+
const globalPath = execSync('npm root -g', { encoding: 'utf8' }).trim();
|
|
88
|
+
const typescriptPath = path.join(globalPath, 'typescript');
|
|
89
|
+
|
|
90
|
+
if (fs.existsSync(typescriptPath)) {
|
|
91
|
+
// tslint:disable-next-line:no-var-requires
|
|
92
|
+
return require(typescriptPath);
|
|
93
|
+
}
|
|
94
|
+
} catch {
|
|
95
|
+
// Fall through
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function tryResolveViaTemporaryInstall(): any {
|
|
102
|
+
try {
|
|
103
|
+
const tmpDir = path.join(require('os').tmpdir(), 'devextreme-schematics-ts-' + Date.now());
|
|
104
|
+
fs.mkdirSync(tmpDir, { recursive: true });
|
|
105
|
+
|
|
106
|
+
const packageJson = {
|
|
107
|
+
name: 'temp-typescript-resolver',
|
|
108
|
+
version: '1.0.0',
|
|
109
|
+
dependencies: {
|
|
110
|
+
typescript: 'latest'
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
fs.writeFileSync(
|
|
114
|
+
path.join(tmpDir, 'package.json'),
|
|
115
|
+
JSON.stringify(packageJson, null, 2)
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
execSync('npm install --silent --no-progress', {
|
|
119
|
+
cwd: tmpDir,
|
|
120
|
+
stdio: 'ignore',
|
|
121
|
+
timeout: 30000
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
const typescriptPath = path.join(tmpDir, 'node_modules', 'typescript');
|
|
125
|
+
if (fs.existsSync(typescriptPath)) {
|
|
126
|
+
// tslint:disable-next-line:no-var-requires
|
|
127
|
+
const ts = require(typescriptPath);
|
|
128
|
+
|
|
129
|
+
setTimeout(() => {
|
|
130
|
+
try {
|
|
131
|
+
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
132
|
+
} catch {
|
|
133
|
+
// Ignore cleanup errors
|
|
134
|
+
}
|
|
135
|
+
}, 5000);
|
|
136
|
+
|
|
137
|
+
return ts;
|
|
138
|
+
}
|
|
139
|
+
} catch {
|
|
140
|
+
// Fall through
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
return null;
|
|
144
|
+
}
|