@storm-software/unbuild 0.30.6 → 0.31.1

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.
@@ -35,7 +35,7 @@ import {
35
35
  } from "./chunk-3GQAWCBQ.js";
36
36
 
37
37
  // src/build.ts
38
- import { readCachedProjectGraph as readCachedProjectGraph3, writeJsonFile } from "@nx/devkit";
38
+ import { readCachedProjectGraph as readCachedProjectGraph2, writeJsonFile } from "@nx/devkit";
39
39
  import { getHelperDependency, HelperDependency } from "@nx/js";
40
40
  import { calculateProjectBuildableDependencies as calculateProjectBuildableDependencies2 } from "@nx/js/src/utils/buildable-libs-utils";
41
41
 
@@ -53,10 +53,154 @@ import { stripIndents } from "@nx/devkit";
53
53
  import { relative } from "path";
54
54
 
55
55
  // ../build-tools/src/utilities/copy-assets.ts
56
- import { readCachedProjectGraph, readProjectsConfigurationFromProjectGraph } from "@nx/devkit";
57
- import { copyAssets as copyAssetsBase } from "@nx/js";
56
+ import { CopyAssetsHandler } from "@nx/js/src/utils/assets/copy-assets-handler";
58
57
  import { glob } from "glob";
59
- import { readFile as readFile2, writeFile } from "node:fs/promises";
58
+ import { readFile, writeFile } from "node:fs/promises";
59
+ var copyAssets = /* @__PURE__ */ __name(async (config, assets, outputPath, projectRoot, sourceRoot, generatePackageJson2 = true, includeSrc = false, banner, footer) => {
60
+ const pendingAssets = Array.from(assets ?? []);
61
+ pendingAssets.push({
62
+ input: projectRoot,
63
+ glob: "*.md",
64
+ output: "."
65
+ });
66
+ pendingAssets.push({
67
+ input: ".",
68
+ glob: "LICENSE",
69
+ output: "."
70
+ });
71
+ if (generatePackageJson2 === false) {
72
+ pendingAssets.push({
73
+ input: projectRoot,
74
+ glob: "package.json",
75
+ output: "."
76
+ });
77
+ }
78
+ if (includeSrc === true) {
79
+ pendingAssets.push({
80
+ input: sourceRoot,
81
+ glob: "**/{*.ts,*.tsx,*.js,*.jsx}",
82
+ output: "src/"
83
+ });
84
+ }
85
+ writeTrace(`\u{1F4DD} Copying the following assets to the output directory:
86
+ ${pendingAssets.map((pendingAsset) => typeof pendingAsset === "string" ? ` - ${pendingAsset} -> ${outputPath}` : ` - ${pendingAsset.input}/${pendingAsset.glob} -> ${joinPaths(outputPath, pendingAsset.output)}`).join("\n")}`, config);
87
+ const assetHandler = new CopyAssetsHandler({
88
+ projectDir: projectRoot,
89
+ rootDir: config.workspaceRoot,
90
+ outputDir: outputPath,
91
+ assets: pendingAssets
92
+ });
93
+ await assetHandler.processAllAssetsOnce();
94
+ if (includeSrc === true) {
95
+ writeDebug(`\u{1F4DD} Adding banner and writing source files: ${joinPaths(outputPath, "src")}`, config);
96
+ const files = await glob([
97
+ joinPaths(config.workspaceRoot, outputPath, "src/**/*.ts"),
98
+ joinPaths(config.workspaceRoot, outputPath, "src/**/*.tsx"),
99
+ joinPaths(config.workspaceRoot, outputPath, "src/**/*.js"),
100
+ joinPaths(config.workspaceRoot, outputPath, "src/**/*.jsx")
101
+ ]);
102
+ await Promise.allSettled(files.map(async (file) => writeFile(file, `${banner && typeof banner === "string" ? banner.startsWith("//") ? banner : `// ${banner}` : ""}
103
+
104
+ ${await readFile(file, "utf8")}
105
+
106
+ ${footer && typeof footer === "string" ? footer.startsWith("//") ? footer : `// ${footer}` : ""}`)));
107
+ }
108
+ }, "copyAssets");
109
+
110
+ // ../build-tools/src/utilities/generate-package-json.ts
111
+ import { calculateProjectBuildableDependencies } from "@nx/js/src/utils/buildable-libs-utils";
112
+ import { Glob } from "glob";
113
+ import { existsSync } from "node:fs";
114
+ import { readFile as readFile2 } from "node:fs/promises";
115
+ import { readCachedProjectGraph } from "nx/src/project-graph/project-graph";
116
+ var addPackageDependencies = /* @__PURE__ */ __name(async (workspaceRoot, projectRoot, projectName, packageJson) => {
117
+ const projectDependencies = calculateProjectBuildableDependencies(void 0, readCachedProjectGraph(), workspaceRoot, projectName, process.env.NX_TASK_TARGET_TARGET || "build", process.env.NX_TASK_TARGET_CONFIGURATION || "production", true);
118
+ const localPackages = [];
119
+ for (const project of projectDependencies.dependencies.filter((dep) => dep.node.type === "lib" && dep.node.data.root !== projectRoot && dep.node.data.root !== workspaceRoot)) {
120
+ const projectNode = project.node;
121
+ if (projectNode.data.root) {
122
+ const projectPackageJsonPath = joinPaths(workspaceRoot, projectNode.data.root, "package.json");
123
+ if (existsSync(projectPackageJsonPath)) {
124
+ const projectPackageJsonContent = await readFile2(projectPackageJsonPath, "utf8");
125
+ const projectPackageJson = JSON.parse(projectPackageJsonContent);
126
+ if (projectPackageJson.private !== false) {
127
+ localPackages.push(projectPackageJson);
128
+ }
129
+ }
130
+ }
131
+ }
132
+ if (localPackages.length > 0) {
133
+ writeTrace(`\u{1F4E6} Adding local packages to package.json: ${localPackages.map((p) => p.name).join(", ")}`);
134
+ packageJson.peerDependencies = localPackages.reduce((ret, localPackage) => {
135
+ if (!ret[localPackage.name]) {
136
+ ret[localPackage.name] = `>=${localPackage.version || "0.0.1"}`;
137
+ }
138
+ return ret;
139
+ }, packageJson.peerDependencies ?? {});
140
+ packageJson.peerDependenciesMeta = localPackages.reduce((ret, localPackage) => {
141
+ if (!ret[localPackage.name]) {
142
+ ret[localPackage.name] = {
143
+ optional: false
144
+ };
145
+ }
146
+ return ret;
147
+ }, packageJson.peerDependenciesMeta ?? {});
148
+ packageJson.devDependencies = localPackages.reduce((ret, localPackage) => {
149
+ if (!ret[localPackage.name]) {
150
+ ret[localPackage.name] = localPackage.version || "0.0.1";
151
+ }
152
+ return ret;
153
+ }, packageJson.peerDependencies ?? {});
154
+ } else {
155
+ writeTrace("\u{1F4E6} No local packages dependencies to add to package.json");
156
+ }
157
+ return packageJson;
158
+ }, "addPackageDependencies");
159
+ var addWorkspacePackageJsonFields = /* @__PURE__ */ __name(async (config, projectRoot, sourceRoot, projectName, includeSrc = false, packageJson) => {
160
+ const workspaceRoot = config.workspaceRoot ? config.workspaceRoot : findWorkspaceRoot();
161
+ const workspacePackageJsonContent = await readFile2(joinPaths(workspaceRoot, "package.json"), "utf8");
162
+ const workspacePackageJson = JSON.parse(workspacePackageJsonContent);
163
+ packageJson.type ??= "module";
164
+ packageJson.sideEffects ??= false;
165
+ if (includeSrc === true) {
166
+ let distSrc = sourceRoot.replace(projectRoot, "");
167
+ if (distSrc.startsWith("/")) {
168
+ distSrc = distSrc.substring(1);
169
+ }
170
+ packageJson.source ??= `${joinPaths(distSrc, "index.ts").replaceAll("\\", "/")}`;
171
+ }
172
+ packageJson.files ??= [
173
+ "dist/**/*"
174
+ ];
175
+ if (includeSrc === true && !packageJson.files.includes("src")) {
176
+ packageJson.files.push("src/**/*");
177
+ }
178
+ packageJson.publishConfig ??= {
179
+ access: "public"
180
+ };
181
+ packageJson.description ??= workspacePackageJson.description;
182
+ packageJson.homepage ??= workspacePackageJson.homepage;
183
+ packageJson.bugs ??= workspacePackageJson.bugs;
184
+ packageJson.license ??= workspacePackageJson.license;
185
+ packageJson.keywords ??= workspacePackageJson.keywords;
186
+ packageJson.funding ??= workspacePackageJson.funding;
187
+ packageJson.author ??= workspacePackageJson.author;
188
+ packageJson.maintainers ??= workspacePackageJson.maintainers;
189
+ if (!packageJson.maintainers && packageJson.author) {
190
+ packageJson.maintainers = [
191
+ packageJson.author
192
+ ];
193
+ }
194
+ packageJson.contributors ??= workspacePackageJson.contributors;
195
+ if (!packageJson.contributors && packageJson.author) {
196
+ packageJson.contributors = [
197
+ packageJson.author
198
+ ];
199
+ }
200
+ packageJson.repository ??= workspacePackageJson.repository;
201
+ packageJson.repository.directory ??= projectRoot ? projectRoot : joinPaths("packages", projectName);
202
+ return packageJson;
203
+ }, "addWorkspacePackageJsonFields");
60
204
 
61
205
  // ../config-tools/src/config-file/get-config-file.ts
62
206
  import { loadConfig as loadConfig2 } from "c12";
@@ -584,193 +728,12 @@ var getConfig = /* @__PURE__ */ __name((workspaceRoot, skipLogs = false) => {
584
728
  return loadStormConfig(workspaceRoot, skipLogs);
585
729
  }, "getConfig");
586
730
 
587
- // ../build-tools/src/utilities/read-nx-config.ts
588
- import { existsSync } from "node:fs";
589
- import { readFile } from "node:fs/promises";
590
- var readNxConfig = /* @__PURE__ */ __name(async (workspaceRoot) => {
591
- let rootDir = workspaceRoot;
592
- if (!rootDir) {
593
- const config = await getConfig();
594
- rootDir = config.workspaceRoot;
595
- }
596
- const nxJsonPath = joinPaths(rootDir, "nx.json");
597
- if (!existsSync(nxJsonPath)) {
598
- throw new Error("Cannot find project.json configuration");
599
- }
600
- const configContent = await readFile(nxJsonPath, "utf8");
601
- return JSON.parse(configContent);
602
- }, "readNxConfig");
603
-
604
- // ../build-tools/src/utilities/copy-assets.ts
605
- var copyAssets = /* @__PURE__ */ __name(async (config, assets, outputPath, projectRoot, projectName, sourceRoot, generatePackageJson2 = true, includeSrc = false, banner, footer) => {
606
- const pendingAssets = Array.from(assets ?? []);
607
- pendingAssets.push({
608
- input: joinPaths(config.workspaceRoot, projectRoot),
609
- glob: "*.md",
610
- output: "."
611
- });
612
- pendingAssets.push({
613
- input: config.workspaceRoot,
614
- glob: "LICENSE",
615
- output: "."
616
- });
617
- if (generatePackageJson2 === false) {
618
- pendingAssets.push({
619
- input: projectRoot,
620
- glob: "package.json",
621
- output: "."
622
- });
623
- }
624
- if (includeSrc === true) {
625
- pendingAssets.push({
626
- input: sourceRoot,
627
- glob: "**/{*.ts,*.tsx,*.js,*.jsx}",
628
- output: "src/"
629
- });
630
- }
631
- const nxJson = readNxConfig(config.workspaceRoot);
632
- const projectGraph = readCachedProjectGraph();
633
- const projectsConfigurations = readProjectsConfigurationFromProjectGraph(projectGraph);
634
- if (!projectsConfigurations?.projects?.[projectName]) {
635
- throw new Error("The Build process failed because the project does not have a valid configuration in the project.json file. Check if the file exists in the root of the project.");
636
- }
637
- const buildTarget = projectsConfigurations.projects[projectName].targets?.build;
638
- if (!buildTarget) {
639
- throw new Error(`The Build process failed because the project does not have a valid build target in the project.json file. Check if the file exists in the root of the project at ${joinPaths(projectRoot, "project.json")}`);
640
- }
641
- writeTrace(`\u{1F4DD} Copying the following assets to the output directory:
642
- ${pendingAssets.map((pendingAsset) => typeof pendingAsset === "string" ? ` - ${pendingAsset} -> ${outputPath}` : ` - ${pendingAsset.input}/${pendingAsset.glob} -> ${joinPaths(outputPath, pendingAsset.output)}`).join("\n")}`, config);
643
- const result = await copyAssetsBase({
644
- assets: pendingAssets,
645
- watch: false,
646
- outputPath
647
- }, {
648
- root: config.workspaceRoot,
649
- targetName: "build",
650
- target: buildTarget,
651
- projectName,
652
- projectGraph,
653
- projectsConfigurations,
654
- nxJsonConfiguration: nxJson,
655
- cwd: config.workspaceRoot,
656
- isVerbose: isVerbose(config.logLevel)
657
- });
658
- if (!result.success) {
659
- throw new Error("The Build process failed trying to copy assets");
660
- }
661
- if (includeSrc === true) {
662
- writeDebug(`\u{1F4DD} Adding banner and writing source files: ${joinPaths(outputPath, "src")}`, config);
663
- const files = await glob([
664
- joinPaths(config.workspaceRoot, outputPath, "src/**/*.ts"),
665
- joinPaths(config.workspaceRoot, outputPath, "src/**/*.tsx"),
666
- joinPaths(config.workspaceRoot, outputPath, "src/**/*.js"),
667
- joinPaths(config.workspaceRoot, outputPath, "src/**/*.jsx")
668
- ]);
669
- await Promise.allSettled(files.map(async (file) => writeFile(file, `${banner && typeof banner === "string" ? banner.startsWith("//") ? banner : `// ${banner}` : ""}
670
-
671
- ${await readFile2(file, "utf8")}
672
-
673
- ${footer && typeof footer === "string" ? footer.startsWith("//") ? footer : `// ${footer}` : ""}`)));
674
- }
675
- }, "copyAssets");
731
+ // ../build-tools/src/utilities/get-entry-points.ts
732
+ import { glob as glob2 } from "glob";
676
733
 
677
- // ../build-tools/src/utilities/generate-package-json.ts
678
- import { calculateProjectBuildableDependencies } from "@nx/js/src/utils/buildable-libs-utils";
679
- import { Glob } from "glob";
734
+ // ../build-tools/src/utilities/read-nx-config.ts
680
735
  import { existsSync as existsSync2 } from "node:fs";
681
736
  import { readFile as readFile3 } from "node:fs/promises";
682
- import { readCachedProjectGraph as readCachedProjectGraph2 } from "nx/src/project-graph/project-graph";
683
- var addPackageDependencies = /* @__PURE__ */ __name(async (workspaceRoot, projectRoot, projectName, packageJson) => {
684
- const projectDependencies = calculateProjectBuildableDependencies(void 0, readCachedProjectGraph2(), workspaceRoot, projectName, process.env.NX_TASK_TARGET_TARGET || "build", process.env.NX_TASK_TARGET_CONFIGURATION || "production", true);
685
- const localPackages = [];
686
- for (const project of projectDependencies.dependencies.filter((dep) => dep.node.type === "lib" && dep.node.data.root !== projectRoot && dep.node.data.root !== workspaceRoot)) {
687
- const projectNode = project.node;
688
- if (projectNode.data.root) {
689
- const projectPackageJsonPath = joinPaths(workspaceRoot, projectNode.data.root, "package.json");
690
- if (existsSync2(projectPackageJsonPath)) {
691
- const projectPackageJsonContent = await readFile3(projectPackageJsonPath, "utf8");
692
- const projectPackageJson = JSON.parse(projectPackageJsonContent);
693
- if (projectPackageJson.private !== false) {
694
- localPackages.push(projectPackageJson);
695
- }
696
- }
697
- }
698
- }
699
- if (localPackages.length > 0) {
700
- writeTrace(`\u{1F4E6} Adding local packages to package.json: ${localPackages.map((p) => p.name).join(", ")}`);
701
- packageJson.peerDependencies = localPackages.reduce((ret, localPackage) => {
702
- if (!ret[localPackage.name]) {
703
- ret[localPackage.name] = `>=${localPackage.version || "0.0.1"}`;
704
- }
705
- return ret;
706
- }, packageJson.peerDependencies ?? {});
707
- packageJson.peerDependenciesMeta = localPackages.reduce((ret, localPackage) => {
708
- if (!ret[localPackage.name]) {
709
- ret[localPackage.name] = {
710
- optional: false
711
- };
712
- }
713
- return ret;
714
- }, packageJson.peerDependenciesMeta ?? {});
715
- packageJson.devDependencies = localPackages.reduce((ret, localPackage) => {
716
- if (!ret[localPackage.name]) {
717
- ret[localPackage.name] = localPackage.version || "0.0.1";
718
- }
719
- return ret;
720
- }, packageJson.peerDependencies ?? {});
721
- } else {
722
- writeTrace("\u{1F4E6} No local packages dependencies to add to package.json");
723
- }
724
- return packageJson;
725
- }, "addPackageDependencies");
726
- var addWorkspacePackageJsonFields = /* @__PURE__ */ __name(async (config, projectRoot, sourceRoot, projectName, includeSrc = false, packageJson) => {
727
- const workspaceRoot = config.workspaceRoot ? config.workspaceRoot : findWorkspaceRoot();
728
- const workspacePackageJsonContent = await readFile3(joinPaths(workspaceRoot, "package.json"), "utf8");
729
- const workspacePackageJson = JSON.parse(workspacePackageJsonContent);
730
- packageJson.type ??= "module";
731
- packageJson.sideEffects ??= false;
732
- if (includeSrc === true) {
733
- let distSrc = sourceRoot.replace(projectRoot, "");
734
- if (distSrc.startsWith("/")) {
735
- distSrc = distSrc.substring(1);
736
- }
737
- packageJson.source ??= `${joinPaths(distSrc, "index.ts").replaceAll("\\", "/")}`;
738
- }
739
- packageJson.files ??= [
740
- "dist/**/*"
741
- ];
742
- if (includeSrc === true && !packageJson.files.includes("src")) {
743
- packageJson.files.push("src/**/*");
744
- }
745
- packageJson.publishConfig ??= {
746
- access: "public"
747
- };
748
- packageJson.description ??= workspacePackageJson.description;
749
- packageJson.homepage ??= workspacePackageJson.homepage;
750
- packageJson.bugs ??= workspacePackageJson.bugs;
751
- packageJson.license ??= workspacePackageJson.license;
752
- packageJson.keywords ??= workspacePackageJson.keywords;
753
- packageJson.funding ??= workspacePackageJson.funding;
754
- packageJson.author ??= workspacePackageJson.author;
755
- packageJson.maintainers ??= workspacePackageJson.maintainers;
756
- if (!packageJson.maintainers && packageJson.author) {
757
- packageJson.maintainers = [
758
- packageJson.author
759
- ];
760
- }
761
- packageJson.contributors ??= workspacePackageJson.contributors;
762
- if (!packageJson.contributors && packageJson.author) {
763
- packageJson.contributors = [
764
- packageJson.author
765
- ];
766
- }
767
- packageJson.repository ??= workspacePackageJson.repository;
768
- packageJson.repository.directory ??= projectRoot ? projectRoot : joinPaths("packages", projectName);
769
- return packageJson;
770
- }, "addWorkspacePackageJsonFields");
771
-
772
- // ../build-tools/src/utilities/get-entry-points.ts
773
- import { glob as glob2 } from "glob";
774
737
 
775
738
  // ../build-tools/src/utilities/task-graph.ts
776
739
  import { createTaskGraph, mapTargetDefaultsToDependencies } from "nx/src/tasks-runner/create-task-graph";
@@ -2225,7 +2188,7 @@ async function resolveOptions(options, config) {
2225
2188
  }
2226
2189
  }
2227
2190
  const outputPath = options.outputPath || joinPaths("dist", options.projectRoot);
2228
- const projectGraph = readCachedProjectGraph3();
2191
+ const projectGraph = readCachedProjectGraph2();
2229
2192
  const projectJsonPath = joinPaths(config.workspaceRoot, options.projectRoot, "project.json");
2230
2193
  if (!existsSync4(projectJsonPath)) {
2231
2194
  throw new Error("Cannot find project.json configuration");
@@ -2502,7 +2465,7 @@ __name(executeUnbuild, "executeUnbuild");
2502
2465
  async function copyBuildAssets(options) {
2503
2466
  writeDebug(` \u{1F4CB} Copying asset files to output directory: ${options.outDir}`, options.config);
2504
2467
  const stopwatch = getStopwatch(`${options.name} asset copy`);
2505
- await copyAssets(options.config, options.assets ?? [], options.outDir, options.projectRoot, options.projectName, options.sourceRoot, options.generatePackageJson, options.includeSrc);
2468
+ await copyAssets(options.config, options.assets ?? [], options.outDir, options.projectRoot, options.sourceRoot, options.generatePackageJson, options.includeSrc);
2506
2469
  stopwatch();
2507
2470
  return options;
2508
2471
  }