Skip to content

Commit

Permalink
fix(workspace-tools): Added code to default tsup build options and pa…
Browse files Browse the repository at this point in the history
…ckage.json path in api-extractor
  • Loading branch information
sullivanpj committed Nov 20, 2023
1 parent 408f328 commit f79dbb1
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 24 deletions.
30 changes: 23 additions & 7 deletions packages/workspace-tools/src/executors/tsup/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,23 @@ export default async function runExecutor(
try {
console.log("📦 Running Storm build executor on the workspace");

// #region Apply default options

options.outputPath ??= "dist/{projectRoot}";
options.tsConfig ??= "{projectRoot}/tsconfig.json";
options.banner ??= process.env.STORM_FILE_BANNER;
options.platform ??= "neutral";
options.verbose ??= false;
options.external ??= [];
options.additionalEntryPoints ??= [];
options.assets ??= [];
options.clean ??= true;
options.bundle ??= true;
options.debug ??= false;
options.watch ??= false;
options.define ??= {};
options.env ??= {};

options.verbose &&
console.log(
`⚙️ Executor options:
Expand All @@ -48,6 +65,8 @@ ${Object.keys(options)
`
);

// #endregion Apply default options

// #region Prepare build context variables

if (
Expand Down Expand Up @@ -264,10 +283,7 @@ ${externalDependencies
})
);

const banner = options.banner
? options.banner
: process.env.STORM_TS_FILE_HEADING;
if (banner) {
if (options.banner) {
const files = globSync([
joinPathFragments(context.root, outputPath, "src/**/*.ts"),
joinPathFragments(context.root, outputPath, "src/**/*.tsx"),
Expand All @@ -278,7 +294,7 @@ ${externalDependencies
files.map(file =>
writeFile(
file,
`// ${banner}\n\n${readFileSync(file, "utf-8")}`,
`// ${options.banner}\n\n${readFileSync(file, "utf-8")}`,
"utf-8"
)
)
Expand All @@ -296,8 +312,8 @@ ${externalDependencies

const config = getConfig(sourceRoot, {
...options,
banner: banner
? { js: `// ${banner}`, css: `/* ${banner} */` }
banner: options.banner
? { js: `// ${options.banner}`, css: `/* ${options.banner} */` }
: undefined,
outputPath
});
Expand Down
2 changes: 1 addition & 1 deletion packages/workspace-tools/src/executors/tsup/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"x-completion-type": "file",
"x-completion-glob": "tsconfig.*.json",
"x-priority": "important",
"default": "tsconfig.json"
"default": "{projectRoot}/tsconfig.json"
},
"additionalEntryPoints": {
"type": "array",
Expand Down
75 changes: 62 additions & 13 deletions patches/tsup@8.0.0.patch
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
diff --git a/dist/index.js b/dist/index.js
index 2c8ba016932710c259e84a7a070271eb4f73da5b..598381c431e83b042f4bd4f272897922ff8d5885 100644
index 2c8ba016932710c259e84a7a070271eb4f73da5b..c915d5db8e1a6a21d6d8f0aea898b7a547c8bbd1 100644
--- a/dist/index.js
+++ b/dist/index.js
@@ -1610,8 +1610,35 @@ async function runEsbuild(options, {
buildDependencies,
pluginContainer
}) {
- const pkg = await _chunk7G76EW2Rjs.loadPkg.call(void 0, process.cwd());
- const deps = await _chunk7G76EW2Rjs.getProductionDeps.call(void 0, process.cwd());
+ let pkgPath = options.outDir
+ ? options.outDir
@@ -1603,6 +1603,36 @@ var generateExternal = async (external) => {
}
return result;
};
+
+var packageJsonSearch = (outDir, silent, format, logger) => {
+ let pkgPath = outDir
+ ? outDir
+ : process.cwd();
+
+ !options.silent && logger3.info(format, `⚡ Preparing to run ESBuild: ${pkgPath}`);
+ !silent && logger.info(format, `⚡ Beginning search for package.json file: ${pkgPath}`);
+ if (pkgPath) {
+ const splits = pkgPath.split("/");
+ if (splits.length > 0) {
+ for (let i = 0; i < splits.length - 1; i++) {
+ const packageJsonPath = _path2.default.join(splits.slice(0,
+ splits.length - i).join("/"),
+ "package.json");
+ !options.silent && logger3.info(format,
+ !silent && logger.info(format,
+ `⚡ Searching for package.json file in ${packageJsonPath} (index: ${i})`);
+
+ if (_fs2.default.existsSync(packageJsonPath)) {
+ !options.silent && logger3.info(format,
+ !silent && logger.info(format,
+ `⚡ Found the package.json file in ${packageJsonPath} (index: ${i})`);
+ pkgPath = packageJsonPath.replace("package.json", "");
+ break;
Expand All @@ -33,14 +33,28 @@ index 2c8ba016932710c259e84a7a070271eb4f73da5b..598381c431e83b042f4bd4f272897922
+ }
+ }
+
+ return pkgPath;
+}
+
async function runEsbuild(options, {
format,
css,
@@ -1610,8 +1640,12 @@ async function runEsbuild(options, {
buildDependencies,
pluginContainer
}) {
- const pkg = await _chunk7G76EW2Rjs.loadPkg.call(void 0, process.cwd());
- const deps = await _chunk7G76EW2Rjs.getProductionDeps.call(void 0, process.cwd());
+ const pkgPath = packageJsonSearch(options.outDir, options.silent, format, logger3);
+ logger3.info(format, `⚡ Running ESBuild: ${pkgPath}`);
+
+ const pkg = await _chunk7G76EW2Rjs.loadPkg.call(void 0, pkgPath);
+ const deps = await _chunk7G76EW2Rjs.getProductionDeps.call(void 0, pkgPath);
+
const external = [
// Exclude dependencies, e.g. `lodash`, `lodash/get`
...deps.map((dep) => new RegExp(`^${dep}($|\\/|\\\\)`)),
@@ -1724,15 +1751,16 @@ async function runEsbuild(options, {
@@ -1724,15 +1758,16 @@ async function runEsbuild(options, {
}, {})
},
inject: [
Expand All @@ -60,3 +74,38 @@ index 2c8ba016932710c259e84a7a070271eb4f73da5b..598381c431e83b042f4bd4f272897922
minify: options.minify === "terser" ? false : options.minify,
minifyWhitespace: options.minifyWhitespace,
minifyIdentifiers: options.minifyIdentifiers,
@@ -2429,8 +2464,10 @@ function formatDistributionExport(declaration, dest) {
// src/api-extractor.ts
var logger2 = _chunk7G76EW2Rjs.createLogger.call(void 0, );
function rollupDtsFile(inputFilePath, outputFilePath, tsconfigFilePath) {
- let cwd = process.cwd();
- let packageJsonFullPath = _path2.default.join(cwd, "package.json");
+ let pkgPath = packageJsonSearch(outputFilePath, false, "dts", logger2);
+ logger2.info("dts", `⚡ Preparing to run API Extractor (DTS generate): ${pkgPath}`);
+
+ let packageJsonFullPath = _path2.default.join(pkgPath, "package.json");
let configObject = {
mainEntryPointFilePath: inputFilePath,
apiReport: {
@@ -2447,7 +2484,7 @@ function rollupDtsFile(inputFilePath, outputFilePath, tsconfigFilePath) {
compiler: {
tsconfigFilePath
},
- projectFolder: cwd
+ projectFolder: pkgPath
};
const prepareOptions = {
configObject,
@@ -2477,7 +2514,11 @@ function rollupDtsFile(inputFilePath, outputFilePath, tsconfigFilePath) {
async function rollupDtsFiles(options, exports, format) {
let declarationDir = _chunkGQ77QZBOjs.ensureTempDeclarationDir.call(void 0, );
let outDir = options.outDir || "dist";
- let pkg = await _chunk7G76EW2Rjs.loadPkg.call(void 0, process.cwd());
+ let pkgPath = packageJsonSearch(outDir, false, "dts", logger2);
+
+ logger2.info("dts", `⚡ Preparing to run Rollup (DTS generate): ${pkgPath}`);
+ let pkg = await _chunk7G76EW2Rjs.loadPkg.call(void 0, pkgPath);
+
let dtsExtension = _chunkGQ77QZBOjs.defaultOutExtension.call(void 0, { format, pkgType: pkg.type }).dts;
let dtsInputFilePath = _path2.default.join(
declarationDir,
6 changes: 3 additions & 3 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 f79dbb1

Please sign in to comment.