@ngrs/nx 0.0.0-stage → 0.2.0

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 CHANGED
@@ -1,3 +1,11 @@
1
- # Temporary Holding Version
1
+ # `@ngrs/nx`
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ First-class **Nx Monorepo** plugin, executors (`application`, `browser-esbuild`, `browser`, `dev-server`, `unit-test`, `extract-i18n`, `package`), and `init` generator for `ngrs`.
4
+
5
+ ## Quick Setup (1 Command)
6
+
7
+ ```bash
8
+ npx nx add @ngrs/nx
9
+ ```
10
+
11
+ Automatically migrates `nx.json` and all `apps/**/project.json` + `libs/**/project.json` targets to `@ngrs/nx:*` with `happy-dom` Vitest unit tests and Nx Computation Caching (`createNodesV2`).
package/executors.json ADDED
@@ -0,0 +1,76 @@
1
+ {
2
+ "executors": {
3
+ "application": {
4
+ "implementation": "./src/executors/application/index.cjs",
5
+ "schema": "./src/executors/application/schema.json",
6
+ "description": "Build an Angular application in an Nx workspace using @ngrs/build & Vite Rolldown."
7
+ },
8
+ "browser-esbuild": {
9
+ "implementation": "./src/executors/application/index.cjs",
10
+ "schema": "./src/executors/application/schema.json",
11
+ "description": "Build an Angular browser application (esbuild-compatible) in an Nx workspace."
12
+ },
13
+ "browser": {
14
+ "implementation": "./src/executors/application/index.cjs",
15
+ "schema": "./src/executors/application/schema.json",
16
+ "description": "Build an Angular browser application (legacy browser executor compatible) in an Nx workspace."
17
+ },
18
+ "dev-server": {
19
+ "implementation": "./src/executors/dev-server/index.cjs",
20
+ "schema": "./src/executors/dev-server/schema.json",
21
+ "description": "Start the Vite 8 HMR development server for an Nx Angular application."
22
+ },
23
+ "unit-test": {
24
+ "implementation": "./src/executors/unit-test/index.cjs",
25
+ "schema": "./src/executors/unit-test/schema.json",
26
+ "description": "Run Vitest unit tests for an Nx Angular application or library."
27
+ },
28
+ "extract-i18n": {
29
+ "implementation": "./src/executors/extract-i18n/index.cjs",
30
+ "schema": "./src/executors/extract-i18n/schema.json",
31
+ "description": "Extract Angular i18n messages in an Nx workspace."
32
+ },
33
+ "package": {
34
+ "implementation": "./src/executors/package/index.cjs",
35
+ "schema": "./src/executors/package/schema.json",
36
+ "description": "Build a publishable/buildable Nx Angular library with native Rust Ivy partial/full compilation."
37
+ }
38
+ },
39
+ "builders": {
40
+ "application": {
41
+ "implementation": "./src/executors/application/index.cjs",
42
+ "schema": "./src/executors/application/schema.json",
43
+ "description": "Build an Angular application in an Nx workspace."
44
+ },
45
+ "browser-esbuild": {
46
+ "implementation": "./src/executors/application/index.cjs",
47
+ "schema": "./src/executors/application/schema.json",
48
+ "description": "Build an Angular browser application in an Nx workspace."
49
+ },
50
+ "browser": {
51
+ "implementation": "./src/executors/application/index.cjs",
52
+ "schema": "./src/executors/application/schema.json",
53
+ "description": "Build an Angular browser application in an Nx workspace."
54
+ },
55
+ "dev-server": {
56
+ "implementation": "./src/executors/dev-server/index.cjs",
57
+ "schema": "./src/executors/dev-server/schema.json",
58
+ "description": "Serve an Angular application in an Nx workspace."
59
+ },
60
+ "unit-test": {
61
+ "implementation": "./src/executors/unit-test/index.cjs",
62
+ "schema": "./src/executors/unit-test/schema.json",
63
+ "description": "Run Vitest unit tests in an Nx workspace."
64
+ },
65
+ "extract-i18n": {
66
+ "implementation": "./src/executors/extract-i18n/index.cjs",
67
+ "schema": "./src/executors/extract-i18n/schema.json",
68
+ "description": "Extract i18n messages in an Nx workspace."
69
+ },
70
+ "package": {
71
+ "implementation": "./src/executors/package/index.cjs",
72
+ "schema": "./src/executors/package/schema.json",
73
+ "description": "Build an Angular library in an Nx workspace."
74
+ }
75
+ }
76
+ }
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "@ngrs/nx",
3
+ "version": "0.2.0",
4
+ "generators": {
5
+ "init": {
6
+ "factory": "./src/generators/init/index.cjs",
7
+ "schema": "./src/generators/init/schema.json",
8
+ "description": "Initialize @ngrs/nx in an Nx monorepo and migrate Angular project.json / nx.json targets.",
9
+ "hidden": false,
10
+ "aliases": [
11
+ "ng-add",
12
+ "install"
13
+ ]
14
+ },
15
+ "ng-add": {
16
+ "factory": "./src/generators/init/index.cjs",
17
+ "schema": "./src/generators/init/schema.json",
18
+ "description": "Add @ngrs/nx to an Nx workspace (`nx add @ngrs/nx`).",
19
+ "hidden": true
20
+ }
21
+ },
22
+ "schematics": {
23
+ "init": {
24
+ "factory": "./src/generators/init/index.cjs",
25
+ "schema": "./src/generators/init/schema.json",
26
+ "description": "Initialize @ngrs/nx in an Nx monorepo."
27
+ },
28
+ "ng-add": {
29
+ "factory": "./src/generators/init/index.cjs",
30
+ "schema": "./src/generators/init/schema.json",
31
+ "description": "Add @ngrs/nx to an Nx workspace."
32
+ }
33
+ }
34
+ }
package/package.json CHANGED
@@ -1,6 +1,87 @@
1
1
  {
2
2
  "name": "@ngrs/nx",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.2.0",
4
+ "description": "First-class Nx Monorepo plugin, executors, and generators for @ngrs (Angular build, Vite dev-server, Vitest unit-test, and APF library compilation)",
5
+ "type": "module",
6
+ "executors": "./executors.json",
7
+ "builders": "./executors.json",
8
+ "generators": "./generators.json",
9
+ "schematics": "./generators.json",
10
+ "ng-add": {
11
+ "save": "devDependencies"
12
+ },
13
+ "main": "./src/index.cjs",
14
+ "module": "./src/index.mjs",
15
+ "types": "./src/index.d.ts",
16
+ "exports": {
17
+ ".": {
18
+ "types": "./src/index.d.ts",
19
+ "import": "./src/index.mjs",
20
+ "require": "./src/index.cjs"
21
+ },
22
+ "./plugin": {
23
+ "import": "./src/plugin.mjs",
24
+ "require": "./src/plugin.cjs"
25
+ },
26
+ "./executors/*": "./src/executors/*",
27
+ "./generators/*": "./src/generators/*",
28
+ "./executors.json": "./executors.json",
29
+ "./generators.json": "./generators.json",
30
+ "./package.json": "./package.json"
31
+ },
32
+ "files": [
33
+ "executors.json",
34
+ "generators.json",
35
+ "src"
36
+ ],
37
+ "dependencies": {
38
+ "@ngrs/build": "0.2.0",
39
+ "@ngrs/compiler": "0.2.0",
40
+ "@ngrs/vite": "0.2.0",
41
+ "happy-dom": "^20.0.0",
42
+ "jsonc-parser": "^3.3.1",
43
+ "picomatch": "^4.0.2"
44
+ },
45
+ "peerDependencies": {
46
+ "@nx/devkit": ">=17.0.0",
47
+ "nx": ">=17.0.0",
48
+ "vitest": ">=2.0.0 || ^4.0.0"
49
+ },
50
+ "peerDependenciesMeta": {
51
+ "@nx/devkit": {
52
+ "optional": true
53
+ },
54
+ "nx": {
55
+ "optional": true
56
+ },
57
+ "vitest": {
58
+ "optional": true
59
+ }
60
+ },
61
+ "engines": {
62
+ "node": ">=18.19.0"
63
+ },
64
+ "keywords": [
65
+ "angular",
66
+ "nx",
67
+ "monorepo",
68
+ "vite",
69
+ "rolldown",
70
+ "vitest",
71
+ "happy-dom",
72
+ "rust"
73
+ ],
74
+ "publishConfig": {
75
+ "access": "public"
76
+ },
77
+ "license": "MIT",
78
+ "repository": {
79
+ "type": "git",
80
+ "url": "git+https://github.com/truonglv95/ngrs.git",
81
+ "directory": "packages/nx"
82
+ },
83
+ "homepage": "https://github.com/truonglv95/ngrs#readme",
84
+ "bugs": {
85
+ "url": "https://github.com/truonglv95/ngrs/issues"
86
+ }
87
+ }
@@ -0,0 +1,10 @@
1
+ 'use strict';
2
+
3
+ async function* applicationExecutorCjs(options, context, extensions) {
4
+ const mod = await import('./index.mjs');
5
+ yield* mod.applicationExecutor(options, context, extensions);
6
+ }
7
+
8
+ module.exports = applicationExecutorCjs;
9
+ module.exports.default = applicationExecutorCjs;
10
+ module.exports.applicationExecutor = applicationExecutorCjs;
@@ -0,0 +1,17 @@
1
+ import { buildApplication } from '@ngrs/build';
2
+ import { toArchitectContext } from '../context-adapter.mjs';
3
+
4
+ export async function* applicationExecutor(options = {}, context = {}, extensions) {
5
+ const { builderContext } = await toArchitectContext(
6
+ options,
7
+ context,
8
+ '@ngrs/nx:application',
9
+ );
10
+ try {
11
+ yield* buildApplication(options, builderContext, extensions);
12
+ } finally {
13
+ await builderContext.runTeardowns();
14
+ }
15
+ }
16
+
17
+ export default applicationExecutor;
@@ -0,0 +1,32 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema",
3
+ "title": "@ngrs/nx Application Executor Schema",
4
+ "description": "Build an Angular application in an Nx workspace using @ngrs/build & Vite 8 Rolldown.",
5
+ "type": "object",
6
+ "properties": {
7
+ "browser": { "type": "string" },
8
+ "main": { "type": "string" },
9
+ "tsConfig": { "type": "string" },
10
+ "outputPath": {
11
+ "oneOf": [{ "type": "string" }, { "type": "object" }]
12
+ },
13
+ "index": {
14
+ "oneOf": [{ "type": "string" }, { "type": "object" }, { "type": "boolean" }]
15
+ },
16
+ "polyfills": {
17
+ "oneOf": [{ "type": "array", "items": { "type": "string" } }, { "type": "string" }]
18
+ },
19
+ "assets": { "type": "array" },
20
+ "styles": { "type": "array" },
21
+ "scripts": { "type": "array" },
22
+ "fileReplacements": { "type": "array" },
23
+ "optimization": { "oneOf": [{ "type": "boolean" }, { "type": "object" }] },
24
+ "sourceMap": { "oneOf": [{ "type": "boolean" }, { "type": "object" }] },
25
+ "outputHashing": { "type": "string" },
26
+ "budgets": { "type": "array" },
27
+ "watch": { "type": "boolean" },
28
+ "verbose": { "type": "boolean" },
29
+ "progress": { "type": "boolean" }
30
+ },
31
+ "additionalProperties": true
32
+ }
@@ -0,0 +1,62 @@
1
+ import path from 'node:path';
2
+ import {
3
+ createConsoleLogger,
4
+ createWorkspaceBuilderContext,
5
+ loadWorkspace,
6
+ resolveProjectName,
7
+ } from '@ngrs/build';
8
+
9
+ /**
10
+ * Adapts an Nx `ExecutorContext` (or Angular Architect `BuilderContext`) into an `@ngrs/build`
11
+ * workspace + `BuilderContext`, working seamlessly whether the workspace uses `project.json` +
12
+ * `nx.json` or `angular.json`.
13
+ */
14
+ export async function toArchitectContext(options = {}, context = {}, builderName = '@ngrs/nx:application') {
15
+ const workspaceRoot = path.resolve(
16
+ context?.root || context?.workspaceRoot || options?.workspaceRoot || process.cwd(),
17
+ );
18
+ const verbose = Boolean(options?.verbose ?? context?.isVerbose ?? false);
19
+ const logger = context?.logger || createConsoleLogger(verbose);
20
+
21
+ let workspace = null;
22
+ if (context?.projectsConfigurations?.projects) {
23
+ workspace = {
24
+ version: context.projectsConfigurations.version ?? 2,
25
+ defaultProject: context.nxJsonConfiguration?.defaultProject,
26
+ projects: structuredClone(context.projectsConfigurations.projects),
27
+ };
28
+ } else {
29
+ const loaded = await loadWorkspace(workspaceRoot);
30
+ workspace = loaded.workspace;
31
+ }
32
+
33
+ const requestedProject =
34
+ context?.projectName || context?.target?.project || options?.project;
35
+ const projectName = resolveProjectName(workspace, requestedProject);
36
+ const targetName = context?.targetName || context?.target?.target || 'build';
37
+ const configurationName =
38
+ context?.configurationName || context?.target?.configuration || options?.configuration;
39
+
40
+ const target = {
41
+ project: projectName,
42
+ target: targetName,
43
+ ...(configurationName ? { configuration: configurationName } : {}),
44
+ };
45
+
46
+ const builderContext = createWorkspaceBuilderContext({
47
+ workspaceRoot,
48
+ workspace,
49
+ target,
50
+ builderName,
51
+ logger,
52
+ });
53
+
54
+ return {
55
+ workspaceRoot,
56
+ workspace,
57
+ projectName,
58
+ target,
59
+ logger,
60
+ builderContext,
61
+ };
62
+ }
@@ -0,0 +1,10 @@
1
+ 'use strict';
2
+
3
+ async function* devServerExecutorCjs(options, context, extensions) {
4
+ const mod = await import('./index.mjs');
5
+ yield* mod.devServerExecutor(options, context, extensions);
6
+ }
7
+
8
+ module.exports = devServerExecutorCjs;
9
+ module.exports.default = devServerExecutorCjs;
10
+ module.exports.devServerExecutor = devServerExecutorCjs;
@@ -0,0 +1,17 @@
1
+ import { executeDevServerBuilder } from '@ngrs/build';
2
+ import { toArchitectContext } from '../context-adapter.mjs';
3
+
4
+ export async function* devServerExecutor(options = {}, context = {}, extensions) {
5
+ const { builderContext } = await toArchitectContext(
6
+ options,
7
+ context,
8
+ '@ngrs/nx:dev-server',
9
+ );
10
+ try {
11
+ yield* executeDevServerBuilder(options, builderContext, extensions);
12
+ } finally {
13
+ await builderContext.runTeardowns();
14
+ }
15
+ }
16
+
17
+ export default devServerExecutor;
@@ -0,0 +1,19 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema",
3
+ "title": "@ngrs/nx Dev-Server Executor Schema",
4
+ "description": "Start the Vite 8 HMR development server for an Nx Angular application.",
5
+ "type": "object",
6
+ "properties": {
7
+ "buildTarget": { "type": "string" },
8
+ "browserTarget": { "type": "string" },
9
+ "port": { "type": "number", "default": 4200 },
10
+ "host": { "type": "string", "default": "localhost" },
11
+ "proxyConfig": { "type": "string" },
12
+ "ssl": { "type": "boolean", "default": false },
13
+ "open": { "type": "boolean", "default": false },
14
+ "hmr": { "type": "boolean", "default": true },
15
+ "liveReload": { "type": "boolean", "default": true },
16
+ "watch": { "type": "boolean", "default": true }
17
+ },
18
+ "additionalProperties": true
19
+ }
@@ -0,0 +1,10 @@
1
+ 'use strict';
2
+
3
+ async function extractI18nExecutorCjs(options, context) {
4
+ const mod = await import('./index.mjs');
5
+ return mod.extractI18nExecutor(options, context);
6
+ }
7
+
8
+ module.exports = extractI18nExecutorCjs;
9
+ module.exports.default = extractI18nExecutorCjs;
10
+ module.exports.extractI18nExecutor = extractI18nExecutorCjs;
@@ -0,0 +1,17 @@
1
+ import { executeExtractI18nBuilder } from '@ngrs/build';
2
+ import { toArchitectContext } from '../context-adapter.mjs';
3
+
4
+ export async function extractI18nExecutor(options = {}, context = {}) {
5
+ const { builderContext } = await toArchitectContext(
6
+ options,
7
+ context,
8
+ '@ngrs/nx:extract-i18n',
9
+ );
10
+ try {
11
+ return await executeExtractI18nBuilder(options, builderContext);
12
+ } finally {
13
+ await builderContext.runTeardowns();
14
+ }
15
+ }
16
+
17
+ export default extractI18nExecutor;
@@ -0,0 +1,13 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema",
3
+ "title": "@ngrs/nx Extract-i18n Executor Schema",
4
+ "description": "Extract Angular i18n messages in an Nx workspace.",
5
+ "type": "object",
6
+ "properties": {
7
+ "buildTarget": { "type": "string" },
8
+ "format": { "type": "string" },
9
+ "outputPath": { "type": "string" },
10
+ "outFile": { "type": "string" }
11
+ },
12
+ "additionalProperties": true
13
+ }
@@ -0,0 +1,10 @@
1
+ 'use strict';
2
+
3
+ async function packageExecutorCjs(options, context) {
4
+ const mod = await import('./index.mjs');
5
+ return mod.packageExecutor(options, context);
6
+ }
7
+
8
+ module.exports = packageExecutorCjs;
9
+ module.exports.default = packageExecutorCjs;
10
+ module.exports.packageExecutor = packageExecutorCjs;
@@ -0,0 +1,209 @@
1
+ import fs from 'node:fs';
2
+ import { copyFile, mkdir, readFile, rm, writeFile } from 'node:fs/promises';
3
+ import { createRequire } from 'node:module';
4
+ import path from 'node:path';
5
+ import { formatBuildMessage, resolveColorsOption, toPosixPath } from '@ngrs/build';
6
+ import { angular, formatDiagnostics } from '@ngrs/vite';
7
+ import { parse as parseJsonc } from 'jsonc-parser';
8
+ import * as vite from 'vite';
9
+ import { toArchitectContext } from '../context-adapter.mjs';
10
+
11
+ const localRequire = createRequire(import.meta.url);
12
+ const { NapiProjectCompiler } = localRequire('@ngrs/compiler');
13
+ const isRolldownVite = 'rolldownVersion' in vite && Boolean(vite.rolldownVersion);
14
+
15
+ function slugifyPackageName(pkgName) {
16
+ return pkgName.replace(/^@/, '').replace(/[\\/]/g, '-');
17
+ }
18
+
19
+ /**
20
+ * `@ngrs/nx:package` executor — builds publishable/buildable Nx Angular libraries (`ng-package.json`
21
+ * or `libs/<name>/package.json`) into Angular Package Format (APF) FESM2022 + `.d.ts` declarations
22
+ * using native Rust `NapiProjectCompiler` (`compilationMode: 'partial'`).
23
+ */
24
+ export async function packageExecutor(options = {}, context = {}) {
25
+ const startTime = performance.now();
26
+ const { workspaceRoot, workspace, projectName, logger } = await toArchitectContext(
27
+ options,
28
+ context,
29
+ '@ngrs/nx:package',
30
+ );
31
+ const colors = resolveColorsOption(options.colors);
32
+ const projectMeta = workspace.projects?.[projectName] || {};
33
+ const projectRoot = path.resolve(workspaceRoot, projectMeta.root || '');
34
+
35
+ // Resolve `ng-package.json` or `package.json`
36
+ let ngPkgConfig = {};
37
+ let ngPkgDir = projectRoot;
38
+ if (typeof options.project === 'string') {
39
+ const absProj = path.resolve(workspaceRoot, options.project);
40
+ ngPkgDir = fs.existsSync(absProj) && fs.statSync(absProj).isDirectory() ? absProj : path.dirname(absProj);
41
+ const candNgPkg = absProj.endsWith('.json') ? absProj : path.join(ngPkgDir, 'ng-package.json');
42
+ if (fs.existsSync(candNgPkg)) {
43
+ ngPkgConfig = parseJsonc(await readFile(candNgPkg, 'utf8'), [], { allowTrailingComma: true }) || {};
44
+ }
45
+ } else {
46
+ const candNgPkg = path.join(projectRoot, 'ng-package.json');
47
+ if (fs.existsSync(candNgPkg)) {
48
+ ngPkgConfig = parseJsonc(await readFile(candNgPkg, 'utf8'), [], { allowTrailingComma: true }) || {};
49
+ }
50
+ }
51
+
52
+ const libPkgPath = path.join(projectRoot, 'package.json');
53
+ const libPkgJson = fs.existsSync(libPkgPath)
54
+ ? JSON.parse(await readFile(libPkgPath, 'utf8'))
55
+ : { name: projectName, version: '0.0.1' };
56
+
57
+ const destDir = options.outputPath
58
+ ? path.resolve(workspaceRoot, options.outputPath)
59
+ : ngPkgConfig.dest
60
+ ? path.resolve(ngPkgDir, ngPkgConfig.dest)
61
+ : path.join(workspaceRoot, 'dist', projectMeta.root || projectName);
62
+
63
+ const entryCandidates = [
64
+ ngPkgConfig?.lib?.entryFile && path.resolve(ngPkgDir, ngPkgConfig.lib.entryFile),
65
+ path.join(projectRoot, 'src', 'index.ts'),
66
+ path.join(projectRoot, 'src', 'public-api.ts'),
67
+ path.join(projectRoot, 'index.ts'),
68
+ ].filter(Boolean);
69
+ const entryFile = entryCandidates.find((p) => fs.existsSync(p));
70
+ if (!entryFile) {
71
+ const msg = `Could not find library entry file (e.g. src/index.ts or src/public-api.ts) in "${projectRoot}".`;
72
+ logger.error(formatBuildMessage(msg, 'error', colors));
73
+ return { success: false, error: msg };
74
+ }
75
+
76
+ const tsconfigCandidates = [
77
+ options.tsConfig && path.resolve(workspaceRoot, options.tsConfig),
78
+ path.join(projectRoot, 'tsconfig.lib.prod.json'),
79
+ path.join(projectRoot, 'tsconfig.lib.json'),
80
+ path.join(projectRoot, 'tsconfig.json'),
81
+ ].filter(Boolean);
82
+ const tsconfigPath = tsconfigCandidates.find((p) => fs.existsSync(p));
83
+ if (!tsconfigPath) {
84
+ const msg = `Could not find library tsconfig.json in "${projectRoot}".`;
85
+ logger.error(formatBuildMessage(msg, 'error', colors));
86
+ return { success: false, error: msg };
87
+ }
88
+
89
+ if (options.deleteOutputPath ?? true) {
90
+ await rm(destDir, { recursive: true, force: true });
91
+ }
92
+ const fesmDir = path.join(destDir, 'fesm2022');
93
+ await mkdir(fesmDir, { recursive: true });
94
+
95
+ const compilationMode = options.compilationMode || 'partial';
96
+ const compiler = NapiProjectCompiler.open(tsconfigPath, {
97
+ compilationMode,
98
+ emitDts: true,
99
+ hmr: false,
100
+ sourceMap: Boolean(options.sourceMap ?? true),
101
+ });
102
+
103
+ const diags = compiler.getDiagnostics();
104
+ const { warnings, errors } = formatDiagnostics(diags, workspaceRoot);
105
+ if (warnings.length > 0) {
106
+ logger.warn(warnings.map((w) => formatBuildMessage(w, 'warning', colors)).join('\n'));
107
+ }
108
+ if (errors.length > 0) {
109
+ logger.error(errors.map((e) => formatBuildMessage(e, 'error', colors)).join('\n'));
110
+ return { success: false, errors };
111
+ }
112
+
113
+ const slug = slugifyPackageName(libPkgJson.name || projectName);
114
+ const fesmFileName = `${slug}.mjs`;
115
+ const bundlerOptionsKey = isRolldownVite ? 'rolldownOptions' : 'rollupOptions';
116
+
117
+ // Bundle FESM2022 module keeping bare npm imports external (standard Angular Package Format)
118
+ await vite.build({
119
+ configFile: false,
120
+ envDir: false,
121
+ root: projectRoot,
122
+ logLevel: 'silent',
123
+ publicDir: false,
124
+ plugins: [
125
+ ...angular({
126
+ tsconfig: tsconfigPath,
127
+ workspaceRoot,
128
+ compilationMode,
129
+ hmr: false,
130
+ emitDts: false,
131
+ deferTypecheck: false,
132
+ suppressViteDiagnosticsLog: true,
133
+ }),
134
+ ],
135
+ build: {
136
+ outDir: fesmDir,
137
+ emptyOutDir: false,
138
+ target: 'es2022',
139
+ minify: false,
140
+ sourcemap: Boolean(options.sourceMap ?? true),
141
+ lib: {
142
+ entry: entryFile,
143
+ formats: ['es'],
144
+ fileName: () => fesmFileName,
145
+ },
146
+ [bundlerOptionsKey]: {
147
+ external: (id) => !id.startsWith('.') && !path.isAbsolute(id) && !id.startsWith('\0'),
148
+ },
149
+ },
150
+ });
151
+
152
+ // Emit `.d.ts` files generated by `NapiProjectCompiler` (`emitDts: true`)
153
+ const sourceBaseDir = path.resolve(path.dirname(entryFile));
154
+ for (const emitted of compiler.getAllEmittedFiles()) {
155
+ if (!emitted.dts) continue;
156
+ const absOut = path.resolve(workspaceRoot, emitted.path);
157
+ if (!absOut.startsWith(sourceBaseDir)) continue;
158
+ if (/\.(?:spec|test)\.[cm]?[jt]sx?$/.test(absOut)) continue;
159
+ const rel = toPosixPath(path.relative(sourceBaseDir, absOut)).replace(
160
+ /\.[cm]?[jt]sx?$/,
161
+ '.d.ts',
162
+ );
163
+ const destDts = path.join(destDir, rel);
164
+ await mkdir(path.dirname(destDts), { recursive: true });
165
+ await writeFile(destDts, emitted.dts, 'utf8');
166
+ }
167
+
168
+ const entryDtsRel =
169
+ './' + toPosixPath(path.relative(sourceBaseDir, entryFile)).replace(/\.tsx?$/, '.d.ts');
170
+ const fesmRel = `./fesm2022/${fesmFileName}`;
171
+
172
+ const outPkgJson = {
173
+ ...libPkgJson,
174
+ sideEffects: libPkgJson.sideEffects ?? false,
175
+ module: fesmRel,
176
+ es2022: fesmRel,
177
+ fesm2022: fesmRel,
178
+ typings: entryDtsRel,
179
+ types: entryDtsRel,
180
+ exports: {
181
+ './package.json': { default: './package.json' },
182
+ '.': {
183
+ types: entryDtsRel,
184
+ es2022: fesmRel,
185
+ esm2022: fesmRel,
186
+ default: fesmRel,
187
+ },
188
+ ...(libPkgJson.exports || {}),
189
+ },
190
+ };
191
+ await writeFile(path.join(destDir, 'package.json'), JSON.stringify(outPkgJson, null, 2) + '\n', 'utf8');
192
+
193
+ const readmeSrc = path.join(projectRoot, 'README.md');
194
+ if (fs.existsSync(readmeSrc)) {
195
+ await copyFile(readmeSrc, path.join(destDir, 'README.md'));
196
+ }
197
+
198
+ const sec = ((performance.now() - startTime) / 1000).toFixed(3);
199
+ logger.info(
200
+ `Built Angular library ${libPkgJson.name || projectName} (${compilationMode} Ivy) to ${destDir} [${sec} seconds]`,
201
+ );
202
+
203
+ return {
204
+ success: true,
205
+ outputPath: destDir,
206
+ };
207
+ }
208
+
209
+ export default packageExecutor;