Skip to content

Commit

Permalink
fix(docs): fix regex that replaces //packages with @bazel
Browse files Browse the repository at this point in the history
It was producing wrong outputs that dropped one path segment.
Also add a better error if the terser_bin attribute is missing (when not in a repo named @npm)
  • Loading branch information
Alex Eagle authored and alexeagle committed Feb 3, 2021
1 parent ea168a7 commit c31c0b6
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 18 deletions.
4 changes: 2 additions & 2 deletions docs/Concatjs.html

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

4 changes: 2 additions & 2 deletions docs/Concatjs.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,14 +204,14 @@ Defaults to `[]`

Defaults to precompiled go binary setup by @bazel/typescript npm package

Defaults to `@npm//@bazel/devserver:devserver`
Defaults to `@npm//@bazel/concatjs/devserver:devserver`

<h4 id="concatjs_devserver-devserver_host">devserver_host</h4>

(*<a href="https://bazel.build/docs/build-ref.html#labels">Label</a>*): Go based devserver executable for the host platform.
Defaults to precompiled go binary setup by @bazel/typescript npm package

Defaults to `@npm//@bazel/devserver:devserver_darwin_amd64`
Defaults to `@npm//@bazel/concatjs/devserver:devserver_darwin_amd64`

<h4 id="concatjs_devserver-entry_module">entry_module</h4>

Expand Down
2 changes: 1 addition & 1 deletion docs/Rollup.html

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

2 changes: 1 addition & 1 deletion docs/Rollup.md
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ Defaults to `@npm//rollup/bin:rollup`

(*<a href="https://bazel.build/docs/build-ref.html#labels">Label</a>*): Internal use only

Defaults to `@npm//@bazel/bin:rollup-worker`
Defaults to `@npm//@bazel/rollup/bin:rollup-worker`

<h4 id="rollup_bundle-silent">silent</h4>

Expand Down
2 changes: 1 addition & 1 deletion docs/Terser.html

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

2 changes: 1 addition & 1 deletion docs/Terser.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,6 @@ If you want to do this, you can pass a filegroup here.

(*<a href="https://bazel.build/docs/build-ref.html#labels">Label</a>*): An executable target that runs Terser

Defaults to `@npm//@bazel/bin:terser`
Defaults to `@npm//@bazel/terser/bin:terser`


4 changes: 2 additions & 2 deletions docs/install.html

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

10 changes: 7 additions & 3 deletions packages/terser/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,12 @@ function main() {
// If necessary, get the new `terser` binary, added for >=4.3.0
terserBinary = terserBinary || require.resolve('terser/bin/terser');
} catch (e) {
// If necessary, get the old `uglifyjs` binary from <4.3.0
terserBinary = terserBinary || require.resolve('terser/bin/uglifyjs');
try {
// If necessary, get the old `uglifyjs` binary from <4.3.0
terserBinary = terserBinary || require.resolve('terser/bin/uglifyjs');
} catch (e) {
throw new Error('terser binary not found. Maybe you need to set the terser_bin attribute?')
}
}
// choose a default concurrency of the number of cores -1 but at least 1.

Expand Down Expand Up @@ -194,4 +198,4 @@ exports.directoryArgs = directoryArgs;

if (require.main === module) {
main();
}
}
9 changes: 4 additions & 5 deletions tools/stardoc/post-process-docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ const content = readFileSync(md, {encoding: 'utf8'});
// @npm is not the required name, but it seems to be the common case
// this reflects the similar transformation made when publishing the packages to npm
// via pkg_npm defined in //tools:defaults.bzl
const out = content
.replace(/(?:@.*)*?\/\/packages\/([^:"\s]*)/g, (str, pkg) => {
const parts = pkg.split('/');
return `@npm//@bazel/${parts[parts.length - 1]}`;
});
const out = content.replace(/(?:@.*)*?\/\/packages\/([^/:"\s]*)/g, (str, pkg) => {
const parts = pkg.split('/');
return `@npm//@bazel/${parts[parts.length - 1]}`;
});

// stamp the frontmatter into the post processed stardoc HTML
const frontmatter = [
Expand Down

0 comments on commit c31c0b6

Please sign in to comment.