@@ -12,10 +12,10 @@ import {
12
12
import { createConsoleLogger , NodeJsSyncHost } from '@angular-devkit/core/node' ;
13
13
import { FileBuffer } from '@angular-devkit/core/src/virtual-fs/host/interface' ;
14
14
15
+ // Importing @angular -devkit/architect here will cause issues importing this file without @angular-devkit/architect installed
15
16
/* eslint-disable no-restricted-imports */
16
17
import type { Architect } from '@angular-devkit/architect' ;
17
- import { WorkspaceNodeModulesArchitectHost } from '@angular-devkit/architect/node' ;
18
- import { NodeModulesBuilderInfo } from '@angular-devkit/architect/node/node-modules-architect-host' ;
18
+ import type { NodeModulesBuilderInfo } from '@angular-devkit/architect/node/node-modules-architect-host' ;
19
19
20
20
import * as chalk from 'chalk' ;
21
21
import { Stats } from 'fs' ;
@@ -52,123 +52,6 @@ import {
52
52
} from '../config/misc-interfaces' ;
53
53
import { readPluginPackageJson } from '../utils/nx-plugin' ;
54
54
55
- class WrappedWorkspaceNodeModulesArchitectHost extends WorkspaceNodeModulesArchitectHost {
56
- private workspaces = new Workspaces ( this . root ) ;
57
-
58
- constructor ( private workspace , private root ) {
59
- super ( workspace , root ) ;
60
- }
61
- async resolveBuilder ( builderStr : string ) : Promise < NodeModulesBuilderInfo > {
62
- const [ packageName , builderName ] = builderStr . split ( ':' ) ;
63
-
64
- const { executorsFilePath, executorConfig } = this . readExecutorsJson (
65
- packageName ,
66
- builderName
67
- ) ;
68
- const builderInfo = this . readExecutor ( packageName , builderName ) ;
69
- return {
70
- name : builderStr ,
71
- builderName,
72
- description :
73
- readJsonFile < ExecutorsJson > ( executorsFilePath ) . builders [ builderName ]
74
- . description ,
75
- optionSchema : builderInfo . schema ,
76
- import : this . workspaces [ 'resolveImplementation' ] . bind ( this . workspaces ) (
77
- executorConfig . implementation ,
78
- dirname ( executorsFilePath )
79
- ) ,
80
- } ;
81
- }
82
-
83
- private readExecutorsJson ( nodeModule : string , builder : string ) {
84
- const { json : packageJson , path : packageJsonPath } = readPluginPackageJson (
85
- nodeModule ,
86
- this . workspaces [ 'resolvePaths' ] . bind ( this . workspaces ) ( )
87
- ) ;
88
- const executorsFile = packageJson . executors ?? packageJson . builders ;
89
-
90
- if ( ! executorsFile ) {
91
- throw new Error (
92
- `The "${ nodeModule } " package does not support Nx executors or Angular Devkit Builders.`
93
- ) ;
94
- }
95
-
96
- const executorsFilePath = require . resolve (
97
- join ( dirname ( packageJsonPath ) , executorsFile )
98
- ) ;
99
- const executorsJson = readJsonFile < ExecutorsJson > ( executorsFilePath ) ;
100
- const executorConfig : {
101
- implementation : string ;
102
- batchImplementation ?: string ;
103
- schema : string ;
104
- hasher ?: string ;
105
- } = executorsJson . builders ?. [ builder ] ;
106
- if ( ! executorConfig ) {
107
- throw new Error (
108
- `Cannot find builder '${ builder } ' in ${ executorsFilePath } .`
109
- ) ;
110
- }
111
- return { executorsFilePath, executorConfig, isNgCompat : true } ;
112
- }
113
-
114
- private readExecutor (
115
- nodeModule : string ,
116
- executor : string
117
- ) : ExecutorConfig & { isNgCompat : boolean } {
118
- try {
119
- const { executorsFilePath, executorConfig, isNgCompat } =
120
- this . readExecutorsJson ( nodeModule , executor ) ;
121
- const executorsDir = dirname ( executorsFilePath ) ;
122
- const schemaPath = this . workspaces [ 'resolveSchema' ] . bind ( this . workspaces ) (
123
- executorConfig . schema ,
124
- executorsDir
125
- ) ;
126
- const schema = normalizeExecutorSchema ( readJsonFile ( schemaPath ) ) ;
127
-
128
- const implementationFactory = this . getImplementationFactory < Executor > (
129
- executorConfig . implementation ,
130
- executorsDir
131
- ) ;
132
-
133
- const batchImplementationFactory = executorConfig . batchImplementation
134
- ? this . getImplementationFactory < TaskGraphExecutor > (
135
- executorConfig . batchImplementation ,
136
- executorsDir
137
- )
138
- : null ;
139
-
140
- const hasherFactory = executorConfig . hasher
141
- ? this . getImplementationFactory < CustomHasher > (
142
- executorConfig . hasher ,
143
- executorsDir
144
- )
145
- : null ;
146
-
147
- return {
148
- schema,
149
- implementationFactory,
150
- batchImplementationFactory,
151
- hasherFactory,
152
- isNgCompat,
153
- } ;
154
- } catch ( e ) {
155
- throw new Error (
156
- `Unable to resolve ${ nodeModule } :${ executor } .\n${ e . message } `
157
- ) ;
158
- }
159
- }
160
-
161
- private getImplementationFactory < T > (
162
- implementation : string ,
163
- executorsDir : string
164
- ) : ( ) => T {
165
- return this . workspaces [ 'getImplementationFactory' ] . bind ( this . workspaces ) (
166
- implementation ,
167
- executorsDir
168
- ) ;
169
- }
170
- }
171
-
172
55
export async function scheduleTarget (
173
56
root : string ,
174
57
opts : {
@@ -194,6 +77,127 @@ export async function scheduleTarget(
194
77
// This happens when context.scheduleTarget is used to run a target using nx:run-commands
195
78
return [ ] ;
196
79
} ) ;
80
+
81
+ const AngularWorkspaceNodeModulesArchitectHost =
82
+ require ( '@angular-devkit/architect/node' ) . WorkspaceNodeModulesArchitectHost ;
83
+
84
+ class WrappedWorkspaceNodeModulesArchitectHost extends AngularWorkspaceNodeModulesArchitectHost {
85
+ private workspaces = new Workspaces ( this . root ) ;
86
+
87
+ constructor ( private workspace , private root ) {
88
+ super ( workspace , root ) ;
89
+ }
90
+ async resolveBuilder ( builderStr : string ) : Promise < NodeModulesBuilderInfo > {
91
+ const [ packageName , builderName ] = builderStr . split ( ':' ) ;
92
+
93
+ const { executorsFilePath, executorConfig } = this . readExecutorsJson (
94
+ packageName ,
95
+ builderName
96
+ ) ;
97
+ const builderInfo = this . readExecutor ( packageName , builderName ) ;
98
+ return {
99
+ name : builderStr ,
100
+ builderName,
101
+ description :
102
+ readJsonFile < ExecutorsJson > ( executorsFilePath ) . builders [ builderName ]
103
+ . description ,
104
+ optionSchema : builderInfo . schema ,
105
+ import : this . workspaces [ 'resolveImplementation' ] . bind ( this . workspaces ) (
106
+ executorConfig . implementation ,
107
+ dirname ( executorsFilePath )
108
+ ) ,
109
+ } ;
110
+ }
111
+
112
+ private readExecutorsJson ( nodeModule : string , builder : string ) {
113
+ const { json : packageJson , path : packageJsonPath } =
114
+ readPluginPackageJson (
115
+ nodeModule ,
116
+ this . workspaces [ 'resolvePaths' ] . bind ( this . workspaces ) ( )
117
+ ) ;
118
+ const executorsFile = packageJson . executors ?? packageJson . builders ;
119
+
120
+ if ( ! executorsFile ) {
121
+ throw new Error (
122
+ `The "${ nodeModule } " package does not support Nx executors or Angular Devkit Builders.`
123
+ ) ;
124
+ }
125
+
126
+ const executorsFilePath = require . resolve (
127
+ join ( dirname ( packageJsonPath ) , executorsFile )
128
+ ) ;
129
+ const executorsJson = readJsonFile < ExecutorsJson > ( executorsFilePath ) ;
130
+ const executorConfig : {
131
+ implementation : string ;
132
+ batchImplementation ?: string ;
133
+ schema : string ;
134
+ hasher ?: string ;
135
+ } = executorsJson . builders ?. [ builder ] ;
136
+ if ( ! executorConfig ) {
137
+ throw new Error (
138
+ `Cannot find builder '${ builder } ' in ${ executorsFilePath } .`
139
+ ) ;
140
+ }
141
+ return { executorsFilePath, executorConfig, isNgCompat : true } ;
142
+ }
143
+
144
+ private readExecutor (
145
+ nodeModule : string ,
146
+ executor : string
147
+ ) : ExecutorConfig & { isNgCompat : boolean } {
148
+ try {
149
+ const { executorsFilePath, executorConfig, isNgCompat } =
150
+ this . readExecutorsJson ( nodeModule , executor ) ;
151
+ const executorsDir = dirname ( executorsFilePath ) ;
152
+ const schemaPath = this . workspaces [ 'resolveSchema' ] . bind (
153
+ this . workspaces
154
+ ) ( executorConfig . schema , executorsDir ) ;
155
+ const schema = normalizeExecutorSchema ( readJsonFile ( schemaPath ) ) ;
156
+
157
+ const implementationFactory = this . getImplementationFactory < Executor > (
158
+ executorConfig . implementation ,
159
+ executorsDir
160
+ ) ;
161
+
162
+ const batchImplementationFactory = executorConfig . batchImplementation
163
+ ? this . getImplementationFactory < TaskGraphExecutor > (
164
+ executorConfig . batchImplementation ,
165
+ executorsDir
166
+ )
167
+ : null ;
168
+
169
+ const hasherFactory = executorConfig . hasher
170
+ ? this . getImplementationFactory < CustomHasher > (
171
+ executorConfig . hasher ,
172
+ executorsDir
173
+ )
174
+ : null ;
175
+
176
+ return {
177
+ schema,
178
+ implementationFactory,
179
+ batchImplementationFactory,
180
+ hasherFactory,
181
+ isNgCompat,
182
+ } ;
183
+ } catch ( e ) {
184
+ throw new Error (
185
+ `Unable to resolve ${ nodeModule } :${ executor } .\n${ e . message } `
186
+ ) ;
187
+ }
188
+ }
189
+
190
+ private getImplementationFactory < T > (
191
+ implementation : string ,
192
+ executorsDir : string
193
+ ) : ( ) => T {
194
+ return this . workspaces [ 'getImplementationFactory' ] . bind ( this . workspaces ) (
195
+ implementation ,
196
+ executorsDir
197
+ ) ;
198
+ }
199
+ }
200
+
197
201
const architectHost = new WrappedWorkspaceNodeModulesArchitectHost (
198
202
workspace ,
199
203
root
1 commit comments
vercel[bot] commentedon Apr 27, 2023
Successfully deployed to the following URLs:
nx-dev – ./
nx-five.vercel.app
nx-dev-git-master-nrwl.vercel.app
nx-dev-nrwl.vercel.app
nx.dev