Skip to content

Commit

Permalink
fix(workspace-tools): Update clean functionality so no previously bui…
Browse files Browse the repository at this point in the history
…ld files are removed
  • Loading branch information
sullivanpj committed Nov 12, 2023
1 parent 30ed069 commit 19ce7bd
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 25 deletions.
1 change: 1 addition & 0 deletions packages/workspace-tools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"@nx/devkit": "17.0.3",
"@nx/esbuild": "17.0.3",
"esbuild-plugin-file-path-extensions": "1.0.0",
"fs-extra": "^11.1.1",
"tslib": "2.6.2",
"tsup": "7.2.0"
},
Expand Down
6 changes: 6 additions & 0 deletions packages/workspace-tools/src/executors/tsup/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { getOutExtension } from "@nx/esbuild/src/executors/esbuild/lib/build-esb
import { getExtraDependencies } from "@nx/esbuild/src/executors/esbuild/lib/get-extra-dependencies";
import { CopyPackageJsonOptions, copyAssets, copyPackageJson } from "@nx/js";
import { DependentBuildableProjectNode } from "@nx/js/src/utils/buildable-libs-utils";
import { removeSync } from "fs-extra";
import { join } from "path";
import { Options, build as tsup } from "tsup";
import { applyWorkspaceTokens } from "../../utils/apply-workspace-tokens";
Expand Down Expand Up @@ -47,6 +48,11 @@ export default async function runExecutor(
context
);

if (options.clean !== false) {
console.log("🧹 Cleaning output path");
removeSync(options.outputPath);
}

const assets = Array.from(options.assets);
assets.push({
input: sourceRoot,
Expand Down
29 changes: 4 additions & 25 deletions packages/workspace-tools/src/executors/tsup/get-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export function modernConfig(
debug = false,
bundle = true,
platform = "neutral",
clean = true,
options: Options = {}
) {
return {
Expand Down Expand Up @@ -39,7 +38,7 @@ export function modernConfig(
platform,
dts: true,
sourcemap: debug,
clean,
clean: false,
esbuildPlugins: [esbuildPluginFilePathExtensions({ esmExtension: "js" })]
} as Options;
}
Expand All @@ -51,7 +50,6 @@ export function legacyConfig(
debug = false,
bundle = true,
platform = "neutral",
clean = true,
options: Options = {}
) {
return {
Expand All @@ -68,7 +66,7 @@ export function legacyConfig(
platform,
dts: true,
sourcemap: debug,
clean,
clean: false,
esbuildPlugins: [esbuildPluginFilePathExtensions({ esmExtension: "js" })]
} as Options;
}
Expand All @@ -79,33 +77,14 @@ export function getConfig({
debug,
bundle,
platform,
clean,
options,
main,
additionalEntryPoints
}: TsupExecutorSchema) {
const entry = [main, ...(additionalEntryPoints ?? [])];

return defineConfig([
modernConfig(
entry,
outputPath,
tsConfig,
debug,
bundle,
platform,
clean,
options
),
legacyConfig(
entry,
outputPath,
tsConfig,
debug,
bundle,
platform,
clean,
options
)
modernConfig(entry, outputPath, tsConfig, debug, bundle, platform, options),
legacyConfig(entry, outputPath, tsConfig, debug, bundle, platform, options)
]);
}
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 19ce7bd

Please sign in to comment.