Skip to content

Commit 5cb7a22

Browse files
committed
fix(nx-infra-plugin): respect BUILD_INTERNAL_PACKAGE env in npm-assemble
1 parent b6f0b7b commit 5cb7a22

2 files changed

Lines changed: 59 additions & 8 deletions

File tree

packages/devextreme/project.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -880,6 +880,7 @@
880880
]
881881
},
882882
"inputs": [
883+
"internalPackageEnv",
883884
"{projectRoot}/artifacts/transpiled-esm-npm/**/*",
884885
"{projectRoot}/js/**/*.json",
885886
"{projectRoot}/license/**/*",
@@ -1128,6 +1129,7 @@
11281129
"parallel": false
11291130
},
11301131
"inputs": [
1132+
"internalPackageEnv",
11311133
"devextremeDistMeta",
11321134
"{workspaceRoot}/packages/devextreme-dist/package.json",
11331135
"{workspaceRoot}/packages/devextreme-scss/scss/**/*",
@@ -1377,7 +1379,8 @@
13771379
"{projectRoot}/webpack.config.js"
13781380
],
13791381
"internalPackageEnv": [
1380-
{ "env": "BUILD_TEST_INTERNAL_PACKAGE" }
1382+
{ "env": "BUILD_TEST_INTERNAL_PACKAGE" },
1383+
{ "env": "BUILD_INTERNAL_PACKAGE" }
13811384
],
13821385
"devextremeDistMeta": [
13831386
"{workspaceRoot}/packages/devextreme-dist/README.md",

packages/nx-infra-plugin/src/executors/npm-assemble/npm-assemble.impl.ts

Lines changed: 55 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,31 @@ import {
2323
NpmAssembleMetadataFile,
2424
} from './schema';
2525

26-
const SRC_JS_EXCLUDES = [
26+
function isInternalPackageBuild(): boolean {
27+
return (
28+
process.env.BUILD_INTERNAL_PACKAGE === 'true'
29+
|| process.env.BUILD_TEST_INTERNAL_PACKAGE === 'true'
30+
);
31+
}
32+
33+
const SRC_JS_BASE_EXCLUDES = [
2734
'bundles/*.js',
2835
'cjs/bundles/**/*',
2936
'esm/bundles/**/*',
3037
'bundles/modules/parts/*.js',
3138
'viz/vector_map.utils/*.js',
3239
'viz/docs/*.js',
33-
'**/license/license_validation_internal.js',
3440
];
3541

42+
function buildSrcJsExcludes(internalBuild: boolean): string[] {
43+
return [
44+
...SRC_JS_BASE_EXCLUDES,
45+
internalBuild
46+
? '**/license/license_validation.js'
47+
: '**/license/license_validation_internal.js',
48+
];
49+
}
50+
3651
const DIST_EXCLUDES = [
3752
'transpiled**/**/*',
3853
'npm/**/*.*',
@@ -61,17 +76,43 @@ const DIST_EXCLUDES = [
6176
'js/dx-quill*',
6277
];
6378

64-
const SRC_JS_HEADER_EXCLUDES = [...SRC_JS_EXCLUDES, 'dist/**/*', 'bin/**/*', 'license/**/*'];
79+
function buildSrcJsHeaderExcludes(internalBuild: boolean): string[] {
80+
return [...buildSrcJsExcludes(internalBuild), 'dist/**/*', 'bin/**/*', 'license/**/*'];
81+
}
6582

6683
const VECTOR_MAP_UTILS_EXCLUDES = ['viz/vector_map.utils/**'];
6784

68-
async function copySourceJs(transpiledDir: string, outputDir: string): Promise<void> {
85+
async function copySourceJs(
86+
transpiledDir: string,
87+
outputDir: string,
88+
internalBuild: boolean,
89+
): Promise<void> {
6990
await copyDirectory(transpiledDir, outputDir, {
7091
include: ['**/*.js'],
71-
exclude: SRC_JS_EXCLUDES,
92+
exclude: buildSrcJsExcludes(internalBuild),
7293
});
7394
}
7495

96+
async function renameInternalLicenseValidator(outputDir: string): Promise<void> {
97+
const licenseDirs = await glob('**/__internal/core/license', {
98+
cwd: toPosixPath(outputDir),
99+
absolute: true,
100+
});
101+
await Promise.all(
102+
licenseDirs.map(async (licenseDir) => {
103+
const internalPath = path.join(licenseDir, 'license_validation_internal.js');
104+
const defaultPath = path.join(licenseDir, 'license_validation.js');
105+
try {
106+
await fs.rename(internalPath, defaultPath);
107+
} catch (error) {
108+
if ((error as NodeJS.ErrnoException).code !== 'ENOENT') {
109+
throw error;
110+
}
111+
}
112+
}),
113+
);
114+
}
115+
75116
async function copyEsmPackageJsonFiles(transpiledDir: string, outputDir: string): Promise<void> {
76117
await copyDirectory(transpiledDir, outputDir, {
77118
include: ['**/*.json'],
@@ -142,6 +183,7 @@ interface ResolvedNpmAssemble {
142183
outputDir: string;
143184
metadataFiles: ResolvedMetadataFile[];
144185
flattenSteps: ResolvedFlattenStep[];
186+
internalBuild: boolean;
145187
}
146188

147189
function resolveMetadataFiles(
@@ -202,6 +244,7 @@ export default createExecutor<NpmAssembleExecutorSchema, ResolvedNpmAssemble>({
202244
outputDir,
203245
metadataFiles: resolveMetadataFiles(options.metadataFiles, projectRoot, outputDir),
204246
flattenSteps: resolveFlattenSteps(options.flatten, projectRoot, outputDir),
247+
internalBuild: isInternalPackageBuild(),
205248
};
206249
},
207250
run: async (resolved) => {
@@ -212,7 +255,7 @@ export default createExecutor<NpmAssembleExecutorSchema, ResolvedNpmAssemble>({
212255
);
213256

214257
await Promise.all([
215-
copySourceJs(resolved.transpiledDir, resolved.outputDir),
258+
copySourceJs(resolved.transpiledDir, resolved.outputDir, resolved.internalBuild),
216259
copyEsmPackageJsonFiles(resolved.transpiledDir, resolved.outputDir),
217260
copyJsSrcJsonFiles(resolved.jsSrcDir, resolved.outputDir),
218261
copyLicenseFiles(resolved.licenseSrcDir, resolved.outputDir),
@@ -222,14 +265,19 @@ export default createExecutor<NpmAssembleExecutorSchema, ResolvedNpmAssemble>({
222265
]);
223266
logger.verbose('Assembled npm package contents');
224267

268+
if (resolved.internalBuild) {
269+
await renameInternalLicenseValidator(resolved.outputDir);
270+
logger.verbose('Renamed internal license validator to default');
271+
}
272+
225273
await applyLicenseHeadersToDirectory({
226274
targetDir: resolved.outputDir,
227275
pkg: resolved.pkg,
228276
templatePath: resolved.templatePath,
229277
eulaUrl: resolved.eulaUrl,
230278
commentType: '*',
231279
includePatterns: ['**/*.js'],
232-
excludePatterns: SRC_JS_HEADER_EXCLUDES,
280+
excludePatterns: buildSrcJsHeaderExcludes(resolved.internalBuild),
233281
filenameMode: 'relative',
234282
});
235283
logger.verbose('Applied star-license banners to source JS files');

0 commit comments

Comments
 (0)