-
-
Notifications
You must be signed in to change notification settings - Fork 205
build: emit to dist/ and ship generated declarations #6092
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
NathanWalker
merged 1 commit into
NativeScript:main
from
edusperoni:chore/build-to-dist
Jul 28, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,150 @@ | ||
| const fs = require("fs"); | ||
| const path = require("path"); | ||
|
|
||
| // dist/ is assembled as a complete package root, not just compiled output: | ||
| // lib/ resolves siblings through __dirname (../package.json, ../docs/helpers, | ||
| // ../../vendor/gradle-plugin, ...), so those directories have to sit next to it | ||
| // exactly as they do in the repo. | ||
|
|
||
| const rootDir = path.join(__dirname, ".."); | ||
| const distDir = path.join(rootDir, "dist"); | ||
| const release = process.argv.includes("--release"); | ||
|
|
||
| // bundleDependencies are resolved from node_modules next to the manifest being | ||
| // packed, so they have to be mirrored into dist for `npm pack` to bundle them | ||
| const BUNDLED = ["universal-analytics", "debug", "ms", "uuid"]; | ||
|
|
||
| const SIBLING_DIRS = ["resources", "docs", "config", "vendor", "bin", "setup"]; | ||
| // npm picks README/LICENSE/CHANGELOG up from the directory being packed, so | ||
| // they have to exist inside dist or they silently drop out of the tarball | ||
| const ROOT_FILES = [ | ||
| "postinstall.js", | ||
| "preuninstall.js", | ||
| "README.md", | ||
| "LICENSE", | ||
| "CHANGELOG.md", | ||
| ]; | ||
|
|
||
| // paths (relative to the repo root) that never ship | ||
| const RELEASE_EXCLUDES = [ | ||
| path.join("docs", "html"), | ||
| path.join("lib", "common", "docs", "fonts"), | ||
| path.join("lib", "common", "test"), | ||
| ]; | ||
|
|
||
| function isExcluded(relPath) { | ||
| if (!release) { | ||
| return false; | ||
| } | ||
| return RELEASE_EXCLUDES.some( | ||
| (excluded) => relPath === excluded || relPath.startsWith(excluded + path.sep) | ||
| ); | ||
| } | ||
|
|
||
| let copied = 0; | ||
| let skipped = 0; | ||
|
|
||
| function copyFile(sourcePath, targetPath) { | ||
| const source = fs.statSync(sourcePath); | ||
| if (fs.existsSync(targetPath)) { | ||
| const target = fs.statSync(targetPath); | ||
| // vendor/ alone is ~31MB; re-copying it on every build is pure waste | ||
| if (target.mtimeMs >= source.mtimeMs && target.size === source.size) { | ||
| skipped++; | ||
| return; | ||
| } | ||
| } | ||
| fs.mkdirSync(path.dirname(targetPath), { recursive: true }); | ||
| fs.copyFileSync(sourcePath, targetPath); | ||
| copied++; | ||
| } | ||
|
|
||
| function copyTree(relDir, filter) { | ||
| const sourceDir = path.join(rootDir, relDir); | ||
| if (!fs.existsSync(sourceDir)) { | ||
| return; | ||
| } | ||
|
|
||
| for (const entry of fs.readdirSync(sourceDir, { withFileTypes: true })) { | ||
| const relPath = path.join(relDir, entry.name); | ||
| if (isExcluded(relPath)) { | ||
| continue; | ||
| } | ||
| if (entry.isDirectory()) { | ||
| copyTree(relPath, filter); | ||
| } else if (!filter || filter(relPath)) { | ||
| copyFile(path.join(rootDir, relPath), path.join(distDir, relPath)); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Everything under lib/ that is not TypeScript is an asset: vendored scripts, | ||
| // hooks, platform-tools binaries, docs helpers and test fixtures. A .js with a | ||
| // sibling .ts is compiler output instead - either left over from the old | ||
| // in-place build or freshly emitted into dist - and copying it would overwrite | ||
| // what tsc just produced. | ||
| function isCompilerOutput(relPath) { | ||
| const stem = relPath.replace(/\.js\.map$/, "").replace(/\.js$/, ""); | ||
| return ( | ||
| (relPath.endsWith(".js") || relPath.endsWith(".js.map")) && | ||
| fs.existsSync(path.join(rootDir, stem + ".ts")) | ||
| ); | ||
| } | ||
|
|
||
| // Hand-written .d.ts come along too. tsc treats them as inputs and never emits | ||
| // them, but the generated declarations import from them, so leaving them behind | ||
| // ships types with dangling references. | ||
| copyTree( | ||
| "lib", | ||
| (relPath) => | ||
| (!relPath.endsWith(".ts") || relPath.endsWith(".d.ts")) && | ||
| !isCompilerOutput(relPath) | ||
| ); | ||
|
|
||
| for (const dir of SIBLING_DIRS) { | ||
| copyTree(dir); | ||
| } | ||
|
|
||
| if (!release) { | ||
| // fixtures the compiled tests read relative to their own location | ||
| copyTree(path.join("test", "files")); | ||
| } | ||
|
|
||
| for (const file of ROOT_FILES) { | ||
| copyFile(path.join(rootDir, file), path.join(distDir, file)); | ||
| } | ||
|
|
||
| for (const dep of BUNDLED) { | ||
| copyTree(path.join("node_modules", dep)); | ||
| } | ||
|
|
||
| writeManifest(); | ||
|
|
||
| function writeManifest() { | ||
| const pkg = JSON.parse( | ||
| fs.readFileSync(path.join(rootDir, "package.json"), "utf8") | ||
| ); | ||
|
|
||
| // dist is the package root once published, so entrypoints lose the dist/ | ||
| // prefix they carry in the source manifest | ||
| pkg.main = pkg.main.replace(/^\.\/dist\//, "./"); | ||
|
|
||
| delete pkg.devDependencies; | ||
| delete pkg.files; | ||
| delete pkg.overrides; | ||
| delete pkg["lint-staged"]; | ||
|
|
||
| pkg.scripts = { | ||
| postinstall: pkg.scripts.postinstall, | ||
| preuninstall: pkg.scripts.preuninstall, | ||
| }; | ||
|
|
||
| fs.writeFileSync( | ||
| path.join(distDir, "package.json"), | ||
| JSON.stringify(pkg, null, 2) + "\n" | ||
| ); | ||
| } | ||
|
|
||
| console.log( | ||
| `assets: ${copied} copied, ${skipped} up to date${release ? " (release)" : ""}` | ||
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| // The published package is assembled in dist/ and packed from there, so packing | ||
| // the repository root would produce a tarball with everything nested one level | ||
| // deeper - every path the CLI resolves through __dirname would break, silently. | ||
| // npm pack ./dist runs dist's own manifest, so this guard does not fire for it. | ||
| console.error( | ||
| [ | ||
| "Refusing to pack the repository root.", | ||
| "", | ||
| "The published package is assembled in dist/. Use:", | ||
| " npm run pack", | ||
| "", | ||
| "which builds dist/ and runs `npm pack ./dist`.", | ||
| ].join("\n") | ||
| ); | ||
|
|
||
| process.exit(1); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: NativeScript/nativescript-cli
Length of output: 1829
Validate the
--dirvalue before resolving it.node scripts/set-ga-id.js live --dirpassesundefinedtopath.resolve, throwing before the usage branch handles invalid input. Gate--diron a non-empty string or--*option and use that target value inpath.resolve.Proposed fix
const dirIndex = process.argv.indexOf("--dir"); +const targetDir = dirIndex === -1 ? undefined : process.argv[dirIndex + 1]; +if (dirIndex !== -1 && (!targetDir || targetDir.startsWith("--"))) { + console.error( + "Usage: node scripts/set-ga-id.js <live|dev|verify> [--dir <path>]" + ); + process.exit(1); +} const baseDir = - dirIndex === -1 ? rootDir : path.resolve(rootDir, process.argv[dirIndex + 1]); + targetDir === undefined ? rootDir : path.resolve(rootDir, targetDir);📝 Committable suggestion
🤖 Prompt for AI Agents