Skip to content

Commit

Permalink
fix(workspace-tools): Enhanced external dependency selection logic
Browse files Browse the repository at this point in the history
  • Loading branch information
sullivanpj committed Nov 30, 2023
1 parent 208766b commit 12dc8d5
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 36 deletions.
2 changes: 1 addition & 1 deletion packages/create-storm-workspace/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ This package is part of the <b>⚡Storm-Ops</b> monorepo. The Storm-Ops packages

<h3 align="center">💻 Visit <a href="https://stormsoftware.org" target="_blank">stormsoftware.org</a> to stay up to date with this developer</h3><br />

[![Version](https://img.shields.io/badge/version-1.16.15-1fb2a6.svg?style=for-the-badge&color=1fb2a6)](https://prettier.io/)&nbsp;
[![Version](https://img.shields.io/badge/version-1.16.19-1fb2a6.svg?style=for-the-badge&color=1fb2a6)](https://prettier.io/)&nbsp;
[![Nx](https://img.shields.io/badge/Nx-17.0.2-lightgrey?style=for-the-badge&logo=nx&logoWidth=20&&color=1fb2a6)](http://nx.dev/)&nbsp;[![NextJs](https://img.shields.io/badge/Next.js-14.0.2-lightgrey?style=for-the-badge&logo=nextdotjs&logoWidth=20&color=1fb2a6)](https://nextjs.org/)&nbsp;[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg?style=for-the-badge&logo=commitlint&color=1fb2a6)](http://commitizen.github.io/cz-cli/)&nbsp;![Semantic-Release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=for-the-badge&color=1fb2a6)&nbsp;[![documented with docusaurus](https://img.shields.io/badge/documented_with-docusaurus-success.svg?style=for-the-badge&logo=readthedocs&color=1fb2a6)](https://docusaurus.io/)&nbsp;![GitHub Workflow Status (with event)](https://img.shields.io/github/actions/workflow/status/storm-software/storm-ops/cr.yml?style=for-the-badge&logo=github-actions&color=1fb2a6)

<h3 align="center" bold="true">⚠️ <b>Attention</b> ⚠️ This repository, and the apps, libraries, and tools contained within, is still in it's initial development phase. As a result, bugs and issues are expected with it's usage. When the main development phase completes, a proper release will be performed, the packages will be availible through NPM (and other distributions), and this message will be removed. However, in the meantime, please feel free to report any issues you may come across.</h3><br />
Expand Down
2 changes: 1 addition & 1 deletion packages/git-tools/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ This package is part of the <b>⚡Storm-Ops</b> monorepo. The Storm-Ops packages

<h3 align="center">💻 Visit <a href="https://stormsoftware.org" target="_blank">stormsoftware.org</a> to stay up to date with this developer</h3><br />

[![Version](https://img.shields.io/badge/version-1.10.14-1fb2a6.svg?style=for-the-badge&color=1fb2a6)](https://prettier.io/)&nbsp;
[![Version](https://img.shields.io/badge/version-1.10.18-1fb2a6.svg?style=for-the-badge&color=1fb2a6)](https://prettier.io/)&nbsp;
[![Nx](https://img.shields.io/badge/Nx-17.0.2-lightgrey?style=for-the-badge&logo=nx&logoWidth=20&&color=1fb2a6)](http://nx.dev/)&nbsp;[![NextJs](https://img.shields.io/badge/Next.js-14.0.2-lightgrey?style=for-the-badge&logo=nextdotjs&logoWidth=20&color=1fb2a6)](https://nextjs.org/)&nbsp;[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg?style=for-the-badge&logo=commitlint&color=1fb2a6)](http://commitizen.github.io/cz-cli/)&nbsp;![Semantic-Release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=for-the-badge&color=1fb2a6)&nbsp;[![documented with docusaurus](https://img.shields.io/badge/documented_with-docusaurus-success.svg?style=for-the-badge&logo=readthedocs&color=1fb2a6)](https://docusaurus.io/)&nbsp;![GitHub Workflow Status (with event)](https://img.shields.io/github/actions/workflow/status/storm-software/storm-ops/cr.yml?style=for-the-badge&logo=github-actions&color=1fb2a6)

<h3 align="center" bold="true">⚠️ <b>Attention</b> ⚠️ This repository, and the apps, libraries, and tools contained within, is still in it's initial development phase. As a result, bugs and issues are expected with it's usage. When the main development phase completes, a proper release will be performed, the packages will be availible through NPM (and other distributions), and this message will be removed. However, in the meantime, please feel free to report any issues you may come across.</h3><br />
Expand Down
2 changes: 1 addition & 1 deletion packages/linting-tools/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ This package is part of the <b>⚡Storm-Ops</b> monorepo. The Storm-Ops packages

<h3 align="center">💻 Visit <a href="https://stormsoftware.org" target="_blank">stormsoftware.org</a> to stay up to date with this developer</h3><br />

[![Version](https://img.shields.io/badge/version-1.12.11-1fb2a6.svg?style=for-the-badge&color=1fb2a6)](https://prettier.io/)&nbsp;
[![Version](https://img.shields.io/badge/version-1.12.15-1fb2a6.svg?style=for-the-badge&color=1fb2a6)](https://prettier.io/)&nbsp;
[![Nx](https://img.shields.io/badge/Nx-17.0.2-lightgrey?style=for-the-badge&logo=nx&logoWidth=20&&color=1fb2a6)](http://nx.dev/)&nbsp;[![NextJs](https://img.shields.io/badge/Next.js-14.0.2-lightgrey?style=for-the-badge&logo=nextdotjs&logoWidth=20&color=1fb2a6)](https://nextjs.org/)&nbsp;[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg?style=for-the-badge&logo=commitlint&color=1fb2a6)](http://commitizen.github.io/cz-cli/)&nbsp;![Semantic-Release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=for-the-badge&color=1fb2a6)&nbsp;[![documented with docusaurus](https://img.shields.io/badge/documented_with-docusaurus-success.svg?style=for-the-badge&logo=readthedocs&color=1fb2a6)](https://docusaurus.io/)&nbsp;![GitHub Workflow Status (with event)](https://img.shields.io/github/actions/workflow/status/storm-software/storm-ops/cr.yml?style=for-the-badge&logo=github-actions&color=1fb2a6)

<h3 align="center" bold="true">⚠️ <b>Attention</b> ⚠️ This repository, and the apps, libraries, and tools contained within, is still in it's initial development phase. As a result, bugs and issues are expected with it's usage. When the main development phase completes, a proper release will be performed, the packages will be availible through NPM (and other distributions), and this message will be removed. However, in the meantime, please feel free to report any issues you may come across.</h3><br />
Expand Down
2 changes: 1 addition & 1 deletion packages/testing-tools/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ This package is part of the <b>⚡Storm-Ops</b> monorepo. The Storm-Ops packages

<h3 align="center">💻 Visit <a href="https://stormsoftware.org" target="_blank">stormsoftware.org</a> to stay up to date with this developer</h3><br />

[![Version](https://img.shields.io/badge/version-1.9.10-1fb2a6.svg?style=for-the-badge&color=1fb2a6)](https://prettier.io/)&nbsp;
[![Version](https://img.shields.io/badge/version-1.9.14-1fb2a6.svg?style=for-the-badge&color=1fb2a6)](https://prettier.io/)&nbsp;
[![Nx](https://img.shields.io/badge/Nx-17.0.2-lightgrey?style=for-the-badge&logo=nx&logoWidth=20&&color=1fb2a6)](http://nx.dev/)&nbsp;[![NextJs](https://img.shields.io/badge/Next.js-14.0.2-lightgrey?style=for-the-badge&logo=nextdotjs&logoWidth=20&color=1fb2a6)](https://nextjs.org/)&nbsp;[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg?style=for-the-badge&logo=commitlint&color=1fb2a6)](http://commitizen.github.io/cz-cli/)&nbsp;![Semantic-Release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=for-the-badge&color=1fb2a6)&nbsp;[![documented with docusaurus](https://img.shields.io/badge/documented_with-docusaurus-success.svg?style=for-the-badge&logo=readthedocs&color=1fb2a6)](https://docusaurus.io/)&nbsp;![GitHub Workflow Status (with event)](https://img.shields.io/github/actions/workflow/status/storm-software/storm-ops/cr.yml?style=for-the-badge&logo=github-actions&color=1fb2a6)

<h3 align="center" bold="true">⚠️ <b>Attention</b> ⚠️ This repository, and the apps, libraries, and tools contained within, is still in it's initial development phase. As a result, bugs and issues are expected with it's usage. When the main development phase completes, a proper release will be performed, the packages will be availible through NPM (and other distributions), and this message will be removed. However, in the meantime, please feel free to report any issues you may come across.</h3><br />
Expand Down
2 changes: 1 addition & 1 deletion packages/workspace-tools/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ This package is part of the <b>⚡Storm-Ops</b> monorepo. The Storm-Ops packages

<h3 align="center">💻 Visit <a href="https://stormsoftware.org" target="_blank">stormsoftware.org</a> to stay up to date with this developer</h3><br />

[![Version](https://img.shields.io/badge/version-1.16.13-1fb2a6.svg?style=for-the-badge&color=1fb2a6)](https://prettier.io/)&nbsp;
[![Version](https://img.shields.io/badge/version-1.16.17-1fb2a6.svg?style=for-the-badge&color=1fb2a6)](https://prettier.io/)&nbsp;
[![Nx](https://img.shields.io/badge/Nx-17.0.2-lightgrey?style=for-the-badge&logo=nx&logoWidth=20&&color=1fb2a6)](http://nx.dev/)&nbsp;[![NextJs](https://img.shields.io/badge/Next.js-14.0.2-lightgrey?style=for-the-badge&logo=nextdotjs&logoWidth=20&color=1fb2a6)](https://nextjs.org/)&nbsp;[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg?style=for-the-badge&logo=commitlint&color=1fb2a6)](http://commitizen.github.io/cz-cli/)&nbsp;![Semantic-Release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=for-the-badge&color=1fb2a6)&nbsp;[![documented with docusaurus](https://img.shields.io/badge/documented_with-docusaurus-success.svg?style=for-the-badge&logo=readthedocs&color=1fb2a6)](https://docusaurus.io/)&nbsp;![GitHub Workflow Status (with event)](https://img.shields.io/github/actions/workflow/status/storm-software/storm-ops/cr.yml?style=for-the-badge&logo=github-actions&color=1fb2a6)

<h3 align="center" bold="true">⚠️ <b>Attention</b> ⚠️ This repository, and the apps, libraries, and tools contained within, is still in it's initial development phase. As a result, bugs and issues are expected with it's usage. When the main development phase completes, a proper release will be performed, the packages will be availible through NPM (and other distributions), and this message will be removed. However, in the meantime, please feel free to report any issues you may come across.</h3><br />
Expand Down
61 changes: 43 additions & 18 deletions packages/workspace-tools/src/executors/tsup/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { readFileSync, writeFileSync } from "fs";
import { removeSync } from "fs-extra";
import { writeFile } from "fs/promises";
import { globSync } from "glob";
import { EventEmitter } from "node:events";
import { buildProjectGraphWithoutDaemon } from "nx/src/project-graph/project-graph";
import { fileExists } from "nx/src/utils/fileutils";
import { dirname, join } from "path";
Expand Down Expand Up @@ -151,7 +150,24 @@ ${Object.keys(options)

// #region Generate the package.json file

const workspacePackageJson = readJsonFile(
join(workspaceRoot, "package.json")
);

options.external = options.external || [];
if (workspacePackageJson?.dependencies) {
options.external = Object.keys(workspacePackageJson?.dependencies).reduce(
(ret: string[], key: string) => {
if (!options.external.includes(key)) {
ret.push(key);
}

return ret;
},
options.external
);
}

const externalDependencies: DependentBuildableProjectNode[] =
options.external.reduce((acc, name) => {
const externalNode = context.projectGraph.externalNodes[`npm:${name}`];
Expand All @@ -161,7 +177,17 @@ ${Object.keys(options)
outputs: [],
node: externalNode
});
} else {
const workspaceNode = context.projectGraph.nodes[name];
if (workspaceNode) {
acc.push({
name,
outputs: [],
node: workspaceNode
});
}
}

return acc;
}, []);
options.verbose &&
Expand All @@ -172,7 +198,7 @@ ${externalDependencies
})
.join("\n")}`);

if (!options.bundle) {
if (options.bundle === false) {
for (const thirdPartyDependency of getExtraDependencies(
context.projectName,
context.projectGraph
Expand All @@ -192,31 +218,35 @@ ${externalDependencies
const packageJson = fileExists(pathToPackageJson)
? readJsonFile(pathToPackageJson)
: { name: context.projectName, version: "0.0.1" };

const workspacePackageJson = readJsonFile(
join(workspaceRoot, "package.json")
);

externalDependencies.forEach(entry => {
const packageConfig = entry.node.data as PackageConfiguration;
if (
packageConfig?.packageName &&
!!(projectGraph.externalNodes[entry.node.name]?.type === "npm")
(!!(projectGraph.externalNodes[entry.node.name]?.type === "npm") ||
!!projectGraph.nodes[entry.node.name])
) {
const { packageName, version } = packageConfig;
if (
/*if (
packageJson.dependencies?.[packageName] ||
packageJson.devDependencies?.[packageName] ||
packageJson.peerDependencies?.[packageName]
) {
return;
}
if (workspacePackageJson.dependencies?.[packageName]) {
}*/

if (
workspacePackageJson.dependencies?.[packageName] ||
workspacePackageJson.devDependencies?.[packageName]
) {
return;
}

packageJson.dependencies ??= {};
packageJson.dependencies[packageName] = version;
packageJson.dependencies[packageName] = !!projectGraph.nodes[
entry.node.name
]
? "latest"
: version;
}
});

Expand Down Expand Up @@ -262,7 +292,7 @@ ${externalDependencies
distSrc = distSrc.substring(1);
}

packageJson.source ??= `./${join(distSrc, "index.ts").replaceAll(
packageJson.source ??= `${join(distSrc, "index.ts").replaceAll(
"\\",
"/"
)}`;
Expand Down Expand Up @@ -350,11 +380,6 @@ ${externalDependencies

// #region Run the build process

const eventEmitter = new EventEmitter({ captureRejections: true });
eventEmitter.on("message", event => {
console.log(`📢 Tsup build message: \n`, event);
});

const config = getConfig(context.root, projectRoot, sourceRoot, {
...options,
dtsTsConfig: getNormalizedTsConfig(
Expand Down
14 changes: 1 addition & 13 deletions packages/workspace-tools/src/executors/tsup/get-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Path, globSync } from "glob";
import { join } from "path";
import { Options, defineConfig } from "tsup";
import type { ParsedCommandLine } from "typescript";
import { WorkspaceStorage } from "../../utils";
import { removeExtension } from "../../utils/file-path-utils";
import { TsupExecutorSchema } from "./schema";

Expand All @@ -25,7 +24,6 @@ type GetConfigParams = Omit<
apiReport?: boolean;
docModel?: boolean;
tsdocMetadata?: boolean;
tsCdnStorage?: WorkspaceStorage;
dtsTsConfig: ParsedCommandLine;
};

Expand All @@ -45,7 +43,6 @@ export function modernConfig({
tsdocMetadata = true,
define,
env,
tsCdnStorage,
plugins,
dtsTsConfig
}: GetConfigParams) {
Expand Down Expand Up @@ -96,7 +93,6 @@ export function modernConfig({
tsdocMetadata,
sourcemap: debug,
clean: false,
tsCdnStorage,
plugins,
outExtension
} as Options;
Expand All @@ -115,7 +111,6 @@ export function legacyConfig({
verbose = false,
define,
env,
tsCdnStorage,
plugins,
dtsTsConfig
}: GetConfigParams) {
Expand Down Expand Up @@ -155,7 +150,6 @@ export function legacyConfig({
tsdocMetadata: false,
sourcemap: debug,
clean: false,
tsCdnStorage,
plugins,
outExtension
} as Options;
Expand All @@ -176,7 +170,6 @@ export function workerConfig({
tsdocMetadata = true,
define,
env,
tsCdnStorage,
plugins,
dtsTsConfig
}: GetConfigParams) {
Expand All @@ -192,7 +185,7 @@ export function workerConfig({
outDir: join(outDir, "dist"),
silent: !verbose,
metafile: true,
shims: true,
shims: false,
minify: true,
external,
platform: "browser",
Expand All @@ -215,7 +208,6 @@ export function workerConfig({
tsdocMetadata,
sourcemap: debug,
clean: false,
tsCdnStorage,
plugins,
outExtension
} as Options;
Expand Down Expand Up @@ -288,10 +280,6 @@ export function getConfig(
tsdocMetadata,
define,
env,
tsCdnStorage: new WorkspaceStorage({
cacheName: "ts-libs",
workspaceRoot
}),
options,
plugins,
dtsTsConfig
Expand Down

0 comments on commit 12dc8d5

Please sign in to comment.