Skip to content

Commit 8f49061

Browse files
Allow running scripts/js from other Node projects (#1747)
This PR allows other repositories to depend on this repo as a VCS requirement, then to run our scripts, like this: ```json "scripts": { "check": "node node_modules/qiskit-documentation/dist/commands/checkMetadata.js" }, "dependencies": { "qiskit-documentation": "qiskit/documentation#3422358984f9ede3a6ac8a2bbe7df517fbd306cb" }, ``` ``` ❯ npm run check > my-function-docs@0.1.0 check:metadata > node node_modules/qiskit-documentation/dist/commands/checkMetadata.js ``` `node_modules/qiskit-documentation` will include only the contents of `src/js` but compiled to JavaScript, along with `package.json`. That results in the other project bringing in all of the transitive dependencies of this repo. Running scripts locally still works. ## Migration to ES Modules Before, we were using CommonJS for how imports and module loading works. However, this was causing issues when trying to run in other repos. The easiest fix was to migrate to ES Modules by setting `"type": "module"` in `package.json`. This required that we set a `.js` file extension in all of our import statements, and that we use `lodash-es` rather than `lodash`. ## Migration to Playwright I could not get Jest to play nicely with TypeScript & ES Modules. The simplest fix was to migrate to Playwright. We already use Playwright in qiskit-sphinx-theme, so this brings nice consistency to the open source projects. ## Followup work: fix individual scripts Some of the scripts may need changes to work in other repositories, like our internal link checker. For now, `checkMetadata.ts` and `checkExternalLinks.ts` definitely work.
1 parent 3f89260 commit 8f49061

68 files changed

Lines changed: 2029 additions & 5616 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,14 @@ docs/.gitkeep
77
.envrc
88
.python-version
99
latex_error.log
10-
1110
.ipynb_checkpoints/
1211
.DS_Store
1312
__pycache__/
14-
1513
node_modules
1614
tsconfig.tsbuildinfo
17-
1815
/.out/
1916
/.sphinx-artifacts/
2017
poetry.lock
21-
2218
.mypy_cache/
19+
/dist/
20+
/test-results/

jest.config.js

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)