@obsidiane/meridiane 2.0.11 → 2.0.13

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@obsidiane/meridiane",
3
- "version": "2.0.11",
3
+ "version": "2.0.13",
4
4
  "description": "Générateur de librairie Angular et modèles TypeScript (OpenAPI) pour un bridge Symfony/API Platform + Mercure.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -23,11 +23,18 @@
23
23
  "README.md"
24
24
  ],
25
25
  "engines": {
26
- "node": ">=20.19"
26
+ "node": ">=24.0.0"
27
27
  },
28
28
  "dependencies": {
29
+ "@angular/common": "20.3.29",
30
+ "@angular/compiler": "20.3.29",
31
+ "@angular/compiler-cli": "20.3.29",
32
+ "@angular/core": "20.3.29",
29
33
  "commander": "^14.0.3",
30
- "handlebars": "^4.7.8",
31
- "tslib": "^2.3.0"
34
+ "handlebars": "^4.7.9",
35
+ "ng-packagr": "20.3.2",
36
+ "rxjs": "7.8.2",
37
+ "tslib": "^2.8.1",
38
+ "typescript": "5.9.3"
32
39
  }
33
40
  }
@@ -1,12 +1,14 @@
1
1
  import process from 'node:process';
2
2
  import path from 'node:path';
3
3
  import fs from 'node:fs/promises';
4
+ import { fileURLToPath } from 'node:url';
4
5
 
5
6
  import { generateBridgeWorkspace } from './generate-bridge.js';
6
7
  import { readOpenApiSpec } from '../infrastructure/spec-loader.js';
7
- import { ensureStandaloneWorkspace, ensureToolchainInstalled } from '../infrastructure/standalone-workspace.js';
8
8
  import { ExitCodeError, runCommand } from '../infrastructure/exec.js';
9
9
 
10
+ const ngPackagrPath = fileURLToPath(import.meta.resolve('ng-packagr/src/cli/main.js'));
11
+
10
12
  export async function runBridgeWorkflow({
11
13
  repoRoot,
12
14
  libName,
@@ -25,15 +27,17 @@ export async function runBridgeWorkflow({
25
27
  packRelativeTo,
26
28
  projectReadmePath,
27
29
  }) {
28
- const { workspaceRoot, distRoot, npmCacheDir, requireFromWs } = await ensureStandaloneWorkspace({ repoRoot, log });
29
- log?.info?.(`workspace: ${workspaceRoot}`);
30
+ const distRoot = path.join(repoRoot, 'dist');
31
+ const buildRoot = path.join(distRoot, '.meridiane-workspace');
32
+ const npmCacheDir = path.join(buildRoot, '.npm-cache');
33
+ await fs.rm(buildRoot, { recursive: true, force: true });
34
+ await fs.mkdir(buildRoot, { recursive: true });
35
+ log?.info?.(`workspace: ${buildRoot}`);
30
36
 
31
37
  const resolvedSpec = await loadSpecIfNeeded({ noModels, spec, specSource, log });
32
38
 
33
- await ensureToolchainInstalled({ workspaceRoot, requireFromWs, npmCacheDir, log });
34
-
35
39
  await generateBridgeWorkspace({
36
- cwd: workspaceRoot,
40
+ cwd: buildRoot,
37
41
  libName,
38
42
  packageName,
39
43
  version,
@@ -49,13 +53,13 @@ export async function runBridgeWorkflow({
49
53
  projectReadmePath,
50
54
  });
51
55
 
52
- const ngPackageJsonPath = path.join(workspaceRoot, 'projects', libName, 'ng-package.json');
53
- const tsconfigAbsPath = path.join(workspaceRoot, 'projects', libName, tsconfigPath);
56
+ const projectDir = path.join(buildRoot, 'projects', libName);
57
+ const ngPackageJsonPath = path.join(projectDir, 'ng-package.json');
58
+ const tsconfigAbsPath = path.join(projectDir, tsconfigPath);
54
59
 
55
60
  log?.step?.('ng-packagr');
56
- const ngPackagrPath = requireFromWs.resolve('ng-packagr/src/cli/main.js');
57
61
  const packagrCode = await runCommand(process.execPath, [ngPackagrPath, '-p', ngPackageJsonPath, '-c', tsconfigAbsPath], {
58
- cwd: workspaceRoot,
62
+ cwd: buildRoot,
59
63
  });
60
64
  if (packagrCode !== 0) throw new ExitCodeError(`ng-packagr failed (exit ${packagrCode})`, packagrCode);
61
65
 
@@ -75,7 +79,7 @@ export async function runBridgeWorkflow({
75
79
  });
76
80
  if (packCode !== 0) throw new ExitCodeError(`npm pack failed (exit ${packCode})`, packCode);
77
81
 
78
- return { workspaceRoot, distRoot, distDir, npmCacheDir };
82
+ return { distDir };
79
83
  }
80
84
 
81
85
  async function loadSpecIfNeeded({ noModels, spec, specSource, log }) {
@@ -1,8 +1,15 @@
1
1
  /* To learn more about Typescript configuration file: https://www.typescriptlang.org/docs/handbook/tsconfig-json.html. */
2
2
  /* To learn more about Angular compiler options: https://angular.dev/reference/configs/angular-compiler-options. */
3
3
  {
4
- "extends": "../../tsconfig.json",
5
4
  "compilerOptions": {
5
+ "target": "ES2022",
6
+ "module": "ES2022",
7
+ "moduleResolution": "bundler",
8
+ "lib": ["ES2022", "DOM"],
9
+ "strict": true,
10
+ "skipLibCheck": true,
11
+ "experimentalDecorators": true,
12
+ "importHelpers": true,
6
13
  "outDir": "../../out-tsc/lib",
7
14
  "declaration": true,
8
15
  "declarationMap": true,
@@ -14,5 +21,9 @@
14
21
  ],
15
22
  "exclude": [
16
23
  "**/*.spec.ts"
17
- ]
24
+ ],
25
+ "angularCompilerOptions": {
26
+ "compilationMode": "partial",
27
+ "strictTemplates": true
28
+ }
18
29
  }
@@ -1,164 +0,0 @@
1
- import fs from 'node:fs/promises';
2
- import path from 'node:path';
3
- import { createRequire } from 'node:module';
4
-
5
- import { runCommand } from './exec.js';
6
- import { writeJsonIfChanged } from './json.js';
7
-
8
- async function ensureDirectory(directory) {
9
- await fs.mkdir(directory, { recursive: true });
10
- }
11
-
12
- async function exists(filePath) {
13
- try {
14
- await fs.stat(filePath);
15
- return true;
16
- } catch {
17
- return false;
18
- }
19
- }
20
-
21
- function toolchainPackageJson({ angularVersion, ngPackagrVersion, typescriptVersion, rxjsVersion, tslibVersion }) {
22
- return {
23
- name: 'meridiane-standalone-workspace',
24
- private: true,
25
- description: 'Temporary workspace created by @obsidiane/meridiane (standalone build).',
26
- devDependencies: {
27
- '@angular/common': angularVersion,
28
- '@angular/compiler': angularVersion,
29
- '@angular/compiler-cli': angularVersion,
30
- '@angular/core': angularVersion,
31
- 'ng-packagr': ngPackagrVersion,
32
- rxjs: rxjsVersion,
33
- tslib: tslibVersion,
34
- typescript: typescriptVersion,
35
- },
36
- };
37
- }
38
-
39
- function rootTsconfigJson() {
40
- return {
41
- compilerOptions: {
42
- target: 'ES2022',
43
- module: 'ES2022',
44
- // Angular >=21 relies on modern package exports resolution for some subpaths
45
- // (e.g. @angular/common/http, @angular/core/rxjs-interop).
46
- moduleResolution: 'bundler',
47
- lib: ['ES2022', 'DOM'],
48
- strict: true,
49
- skipLibCheck: true,
50
- experimentalDecorators: true,
51
- importHelpers: true,
52
- },
53
- angularCompilerOptions: {
54
- compilationMode: 'partial',
55
- strictTemplates: true,
56
- },
57
- };
58
- }
59
-
60
- export async function ensureStandaloneWorkspace({ repoRoot, log }) {
61
- const distRoot = path.join(repoRoot, 'dist');
62
- const workspaceRoot = path.join(distRoot, '.meridiane-workspace');
63
-
64
- await ensureDirectory(distRoot);
65
- await ensureDirectory(workspaceRoot);
66
-
67
- const detected = await detectToolchainVersions(repoRoot);
68
- const angularVersion = detected.angularVersion ?? '21.1.4';
69
- const derived = deriveToolchainDefaultsFromAngular(angularVersion);
70
- const ngPackagrVersion = detected.ngPackagrVersion ?? derived.ngPackagrVersion;
71
- const typescriptVersion = detected.typescriptVersion ?? derived.typescriptVersion;
72
- const rxjsVersion = detected.rxjsVersion ?? '7.8.2';
73
- const tslibVersion = detected.tslibVersion ?? '2.8.1';
74
- log?.debug?.('[meridiane] angular version', { angularVersion });
75
- await writeJsonIfChanged(
76
- path.join(workspaceRoot, 'package.json'),
77
- toolchainPackageJson({ angularVersion, ngPackagrVersion, typescriptVersion, rxjsVersion, tslibVersion })
78
- );
79
- await writeJsonIfChanged(path.join(workspaceRoot, 'tsconfig.json'), rootTsconfigJson());
80
-
81
- const npmCacheDir = path.join(workspaceRoot, '.npm-cache');
82
- await ensureDirectory(npmCacheDir);
83
-
84
- const requireFromWs = createRequire(path.join(workspaceRoot, 'package.json'));
85
-
86
- return { workspaceRoot, distRoot, npmCacheDir, requireFromWs };
87
- }
88
-
89
- async function detectToolchainVersions(repoRoot) {
90
- const packageJsonPath = path.join(repoRoot, 'package.json');
91
- try {
92
- const content = await fs.readFile(packageJsonPath, 'utf8');
93
- const packageJson = JSON.parse(content);
94
- const angularVersion = readDependencyVersion(packageJson, '@angular/core');
95
- const ngPackagrVersion = readDependencyVersion(packageJson, 'ng-packagr');
96
- const typescriptVersion = readDependencyVersion(packageJson, 'typescript');
97
- const rxjsVersion = readDependencyVersion(packageJson, 'rxjs');
98
- const tslibVersion = readDependencyVersion(packageJson, 'tslib');
99
- return { angularVersion, ngPackagrVersion, typescriptVersion, rxjsVersion, tslibVersion };
100
- } catch {
101
- return {};
102
- }
103
- }
104
-
105
- function readDependencyVersion(packageJson, dependencyName) {
106
- const dependencies = packageJson?.dependencies || {};
107
- const devDependencies = packageJson?.devDependencies || {};
108
- const peerDependencies = packageJson?.peerDependencies || {};
109
- const value =
110
- dependencies[dependencyName] ??
111
- devDependencies[dependencyName] ??
112
- peerDependencies[dependencyName];
113
- return typeof value === 'string' && value.trim().length > 0 ? value.trim() : undefined;
114
- }
115
-
116
- function deriveToolchainDefaultsFromAngular(angularVersion) {
117
- const major = parseInt(String(angularVersion).match(/\d+/)?.[0] ?? '0', 10);
118
- if (major >= 21) {
119
- return {
120
- ngPackagrVersion: '21.1.0',
121
- typescriptVersion: '5.9.3',
122
- };
123
- }
124
- return {
125
- ngPackagrVersion: '20.1.0',
126
- typescriptVersion: '5.8.3',
127
- };
128
- }
129
-
130
- export async function ensureToolchainInstalled({ workspaceRoot, requireFromWs, npmCacheDir, log }) {
131
- // Prefer using existing (hoisted) deps during local dev; in CI this will trigger installation.
132
- const canResolve = (packageId) => {
133
- try {
134
- requireFromWs.resolve(packageId);
135
- return true;
136
- } catch {
137
- return false;
138
- }
139
- };
140
-
141
- if (canResolve('ng-packagr/package.json')) return false;
142
-
143
- log?.step?.('installation du toolchain (Angular + ng-packagr)');
144
-
145
- // Use npm with a local cache to avoid writing to ~/.npm.
146
- const env = {
147
- ...process.env,
148
- npm_config_cache: npmCacheDir,
149
- npm_config_update_notifier: 'false',
150
- npm_config_fund: 'false',
151
- npm_config_audit: 'false',
152
- };
153
-
154
- // We avoid generating a lockfile in the backend repo by keeping everything under dist/.
155
- const npmCommand = 'npm';
156
- const args = ['install', '--silent', '--no-progress'];
157
- const code = await runCommand(npmCommand, args, { cwd: workspaceRoot, env });
158
-
159
- if (code !== 0) throw new Error(`Toolchain install failed (npm exit ${code})`);
160
- if (!(await exists(path.join(workspaceRoot, 'node_modules')))) {
161
- throw new Error('Toolchain install failed: node_modules missing');
162
- }
163
- return true;
164
- }