PKG-JS-TOOLS(7)
PKG-JS-TOOLS(7) β the bestie edition π
okay so welcome to the Miscellaneous Information Manual, section 7, and it's literally all about pkg-js-tools β a whole lil collection of tools that helps you package Node modules in Debian. we love to see it π
β¨ NAME β¨
pkg-js-tools β collection of tools to aid packaging Node modules in Debian.
no cap, that's the whole vibe. moving on π
πΈ WORKING WITH SALSA.DEBIAN.ORG REPOSITORY πΈ
so salsa(1) can use the pkg-javascript config, and to make that happen you just add something like this to your .bashrc:
alias js-salsa='salsa --conf-file +/usr/share/pkg-js-tools/pkg-js-salsa.conf'
and then bestie, you can just use salsa like it's nothing. some examples:
- if you made a local repo and you wanna create it and push it on salsa, you literally just launch:
js-salsa push_repo .
- to configure a repo that's already been pushed:
js-salsa update_safe node-foobar
- to clone a js-team package locally:
js-salsa co node-foobar
peep salsa(1) for more. iykyk π¦
π DEBHELPER ADDON π
the pkg-js-tools debhelper addon loads itself automatically if a package build-depends on dh-sequence-nodejs β or, the old fashion way, if dh is called with --with nodejs in debian/rules.
π Quick use
examples of basic migration to pkg-js-tools:
Switch test and install to pkg-js-tools
β How it works
pkg-js-tools provides hooks for these steps:
- configure β populate
node_modules/ - build β build components and main module
- test β test components and main module
- install β install components and main module
- installdocs β can auto-generate docs for each component
- clean β clean pkg-js-tools stuff
technically (and this is the part that's giving "how does she know that"), it adds --buildsystem=nodejs to the corresponding dh_auto_<step> command.
Important note, bestie. Here's the vocab you gotta lock in: - component is the directory name of a submodule (uscan(1)component or additional components listed indebian/nodejs/additional_components). Example:types-glob- module is the npmjs name. Example:@types/glob
See Group Sources Tutorial
for more about embedding components. π
details, and yes i'm listing all of them:
dh_auto_clean, cleans files automatically installed bypkg-js-toolsitselfdh_auto_configure, automatically populatesnode_modulesdirectory:- links embedded components
- links global modules listed in
debian/nodejs/extlinks - copies global modules listed in
debian/nodejs/extcopies
dh_auto_build, Remember to add adh_auto_build --buildsystem=nodejsinoverride_dh_auto_buildsection if yourdebian/rulesfile has such section, else this step will be ignored. (not me warning you fr fr π). Builds:- components by launching
sh -ex debian/nodejs/<component-name>/buildin this file exists - main module by launching
sh -ex debian/nodejs/buildif exists
- components by launching
dh_auto_test, tests:- components by launching
sh -ex debian/nodejs/<component-name>/testif this file exists - main module by launching
sh -ex debian/tests/pkg-js/testif this file exists. This test is also used bypkg-js-autopkgtest(7)during autopkgtest. If you want to have a different test during build, set this test indebian/nodejs/test.
- components by launching
dh_auto_install: installs modules in the good directories and provides some debhelper variables to be used indebian/control. Note that if your package provides more that one binary package, you have to use somedebian/<package-name>.installfiles to distribute the files. Steps:- components: determine files to install using the same algorithm than main module and install them:
- nowhere if component if
debian/nodejs/submodulesexists and component isn't listed in it (an emptydebian/nodejs/submodulesdrops all components) - nowhere if component is listed in
debian/nodejs/additional_componentswith a"!"prefix - in main nodejs directories if component is listed in
debian/nodejs/root_modules - else: in a
node_modulessubdirectory of main module
- nowhere if component if
- main module, determine files to install (see below) and install them in the "good" directory:
- if
"architecture"is"all":/usr/share/nodejs - else:
/usr/lib/${DEB_HOST_MULTIARCH}/nodejs
- if
- links: builds symlinks listed in
debian/nodejs/links. Same usage asdebian/linksexcept that source or destination not starting with/are related to arch path (/usr/share/nodejsor/usr/lib/<gnu-arch>/nodejs) - Build
pkgjs-lock.jsonfiles: if package "maybe a bundle" (built with webpack, browserify,...),pkg-js-toolsbuilds apkgjs-lock.jsonfor each module. This files may help in Debian transitions - Variables usable in
debian/control:${nodejs:Version}: the version of nodejs used during build${nodejs:Provides}: virtual names to be added into"Provides:"field. This lists all modules installed in nodejs root directories${nodeFoo:Provides}: for a source package that provides several binary packages,dh-sequence-nodejsfilters${nodejs:Provides}for each binary package. The package name is converted into its camelcase name:node-jest-workerbecomesnodeJestWorker${nodejs:BuiltUsing}: when package "maybe a bundle", lists packages and versions used to build package. Use it inXB-Javascript-Built-Usingfield
- components: determine files to install using the same algorithm than main module and install them:
dh_installdocs:dh-sequence-nodejsprovides a tool nameddh_nodejs_autodocswhich can be used in aoverride_dh_installdocsto automatically generate documentation for each component. See related manpagedh_install:dh-sequence-nodejsprovides a tool nameddh_nodejs_build_debug_packagewhich can be used to build a separate debug package with sourcemap files when package size is too big. See related manpage
π¦ Automatically detect some additional components π¦
starting from 0.12.0, dh-sequence-nodejs automatically reads lerna.conf and reads "packages" field to find additional components.
starting from 0.12.7, it does the same when package.json has a "workspaces" field.
this auto-detection automatically drops "test" and "tests" directories. You can override this behavior using debian/additional_components.
if a component should not be considered, insert its name preceded by a "!" in debian/nodejs/additional_components.
to disable this feature, use dh-sequence-nodejs-no-lerna. periodt. π
π Algorithm to determine files to install π
pkg-js-tools tries to reproduce npm(1) behavior: it reads package.json and/or .npmignore files to determine files to install except that it drops licenses, *.md, doc*, example*, test*, makefiles,....
this behavior is overridden if:
debian/nodejs/install(ordebian/nodejs/<component-name>/install) exists. This file uses the same format thandebian/install.debian/nodejs/files(ordebian/nodejs/<component-name>/files) exists. the content of this file replaces"files"entry ofpackage.json
π pkg-js-tools files π
- all steps:
debian/nodejs/additional_componentsis used to set some subdirectories that should be considered as components even if they are not listed indebian/watch. Content example:packages/*. Important note: in this example, component name ispackages/fooin every other files, including pathsdebian/nodejs/mainis used to indicates where is the main module. In a package containing only components (bundle package), you should choose one of them as main component
- configure step:
debian/build_modulesadditional modules needed to build, will be linked innode_modulesdirectorydebian/nodejs/component_linkslists needed links between components: links../../component-srcincomponent-dst/node_modules/component-src-namedebian/nodejs/<component-name>/nolinkavoidsnode_moduleslinks creation for this component (configuration step)debian/nodejs/extlinkslists installed node modules that should be linked intonode_modulesdirectory (modules are searched using nodejs algorithm). You can mark them with"test"to avoid errors when build profile containsnocheckdebian/nodejs/extcopieslists installed node modules that should be copied intonode_modulesdirectory. You can also mark them with"test"debian/nodejs/<component>/extlinkslists installed node modules that should be linked in<component>/node_modulesdirectory (test flag available)debian/nodejs/<component>/extcopieslists installed node modules that should be copied in<component>/node_modulesdirectory (test flag available)
- build step:
debian/nodejs/buildcustom build. An empty file stops auto builddebian/nodejs/<component>/build: same for components
πΈ more parts incoming, don't go anywhere bestie πΈ
debian/nodejs/build_orderβ this is the β¨build orderβ¨ list, one component per line. If you don't make one, components get built in alphabetic orderβ¦ except the ones declared indebian/nodejs/component_links, because a component that depends on another one has to be built after it. Dependencies first, bestie, that's just how it is π- π§ͺ test step:
debian/tests/test_modules/β extra modules you need for running tests go in here as subdirectories, and they get linked into thenode_modulesdirectory during the test step only. So they're not hanging around in the final package, ngl very clean of us π§Όdebian/tests/pkg-js/testβ the script that gets launched during test (and yes, it's launched withset -e, so the second something fails, everything stops. no covering things up π)debian/tests/pkg-js/filesβ lists the other files, i.e. anything besidesdebian/tests/test_modules/*and the installed files, that you need for autopkgtest. Default istest*in case you were wondering πdebian/nodejs/testβ overwritesdebian/tests/pkg-js/testduring build, for when the test is different in build vs autopkgtestdebian/nodejs/<component-name>/testβ same idea but for components (and this one is launched during build only)- autopkgtest files:
debian/tests/autopkgtest-pkg-nodejs.confβ an autodep8 configuration file, which lets you add packages or restrictions during autopkgtest onlyextra_depends=p1, p2, p3β permits one to addp1,p2andp3packages π«Άextra-restrictions=needs-internetβ permits one to add additional restrictions during autopkgtest
debian/tests/pkg-js/require-nameβ contains the name to use in the autopkgtest require test, instead of whatever thepackage.jsonvalue says π
- π¦ install step:
debian/nodejs/submodulesβ lists the components to install (all of them if the file is missing)debian/nodejs/root_modulesβ lists components to install in the nodejs root directory, instead of thenode_modulessubdirectory. And if this file contains*, literally all components get installed in the root directory. asterisk ate and left no crumbs βdebian/nodejs/filesβ overwrites thepackage.json#filesfielddebian/nodejs/<component-name>/filesβ overwrites thepackage.json#filesfield, per component. An empty file means avoid any install at all (it's giving "we're not doing that today" π)debian/nodejs/nameβ overwrites thepackage.json#namefielddebian/nodejs/<component-name>/nameβ overwritespackage.json#namefor that componentdebian/nodejs/installβ overwritesdebian/nodejs/files: same usage asdebian/install, except that destinations not starting with/are related to the arch path (/usr/share/nodejsor/usr/lib/<gnu-arch>/nodejs)debian/nodejs/<component-name>/installβ same asdebian/nodejs/installbut for components
- π link step:
debian/nodejs/linksβ same usage asdebian/links, except that a source or destination not starting with/is related to the arch path (/usr/share/nodejsor/usr/lib/<gnu-arch>/nodejs)
NB: To install a component in another directory, set its files in debian/install. βοΈ
Example:
debian/control
...
Testsuite: autopkgtest-pkg-nodejs
Build-Depends: dh-sequence-nodejs
...
debian/tests/pkg-js/test
mocha -R spec
See also pkg-js-autopkgtest README. π
π Multiple binary packages π
When debian/control provides more than one binary package, dh_auto_install populates a debian/tmp, and then dh_install installs files into each package. In that case you must write a debian/<package>.install for every binary package, bestie, no skipping π€ And each line with only one argument is related to debian/tmp.
Examples:
debian/node-arch-indep.installβ pick files fromdebian/tmp:
usr/share/nodejs/foo/
debian/node-arch-dep.installβ pick files fromdebian/tmp:
usr/lib/*/nodejs/foo/
debian/libjs.installβ pick files from sources:
dist/* usr/share/javascript/foo/
π Links π
Since the path is not fixed for an arch-dependent package, you gotta write debian/nodejs/links:
# debian/nodejs/links
foo/bin/cli.js /usr/bin/foo
With an arch independent package, pkg-js-tools transforms this into:
/usr/share/nodejs/foo/bin/cli.js /usr/bin/foo
and for an arch dependent package, it uses DEB_GNU_ARCH. Example with amd64:
/usr/lib/x86_64-linux-gnu/foo/bin/cli.js /usr/bin/foo
All fields that do not start with / are prefixed with the good nodejs path. automagic, literally β¨
π Component docs π
Starting from version 0.13.0, pkg-js-tools provides dh_nodejs_autodocs. This tool automatically installs README.md, CONTRIBUTING.md,β¦ for each root component into its /usr/share/doc/node-<name> directory. And if no debian/*docs is found, it does the same for the main component too. To use it:
override_dh_installdocs:
dh_installdocs
dh_nodejs_autodocs
π« .eslint* files π«
The pkg-js-tools auto installer always removes .eslint* files β unless it's explicitly specified in debian/nodejs/**/files or debian/nodejs/**/install. Not up for debate, sorry π
π΅βπ« Having different test between build and autopkgtest π΅βπ«
When debian/nodejs/test exists, that file is used during the build test instead of debian/tests/pkg-js/test. This permits one to have a different test. You can also just overwrite the dh_auto_test step in debian/rules:
override_dh_auto_test:
# No test during build (test needs Internet)
π Autopkgtest additional test packages or test restrictions π
autodep8 allows one to add additional packages during autopkgtest (and/or additional restrictions) by using a debian/tests/autopkgtest-pkg-nodejs.conf file:
extra_depends=mocha, npm
extra-restrictions=needs-internet
π LINTIAN PROFILES π
pkg-js-tools provides a lintian profile:
pkg-js-extraβ launches additional checks (repo consistency, seedebcheck-node-repobelow) π
To use them:
lintian --profile pkg-js-extra ../node-foo_1.2.3-1.changes
π οΈ OTHER TOOLS π οΈ
See related manpages. π
add-node-componentβ automatically modifiesgbp.confanddebian/watchto add a node component. See JS Group Sources Tutorial. It can also list components or modules (real names)getFromNpmCacheβ export npm cache content to standard outputgithub-debian-upstreamβ launches it in the source repo to create adebian/upstream/metadata(works only if the upstream repo is on GitHub)nodepathβ shows the path of a node module (npm name). You can use-pto show also the Debian package. Option-oshows only the Debian package namedebcheck-node-repoβ checks repo consistency: compares the vcs repo registered in the npm registry with the source repo declared indebian/watch"dh_nodejs_autodocsβ automatically select and install documentation files to install for each componentdh_nodejs_build_debug_packageβ move sourcemap files from binary packages to a separated debug packagemjs2cjsβ build commonjs file using rolluppkgjs-auditβ creates a temporarypackage-lock.jsonfile using the Debian package values used by the module to analyze, and launches anpm audit. If the module is a bundle (and then has apkgjs-lock.json),pkgjs-auditusespkgjs-lock.json, else it generates itspackage-lock.jsonusing available values πpkgjs-dependsβ search recursively the dependencies of the given module name (if not given, uses the currentpackage.json) and displays related Debian packages and missing dependenciespkgjs-installβ same asnpm installbut uses Debian JS modules when availablepkgjs-install-minimalβ same aspkgjs-installbut uses only available Debian modules. It is included indh-nodejsso it can be used during buildpkgjs-lsβ same asnpm lsbut it searches also in global nodejs pathspkgjs-runβ same asnpm runpkgjs-lerna runβ same aslerna run(only the run command is implemented)pkgjs-utils,pkgjs-ln,pkgjs-main,pkgjs-pjsonβ various utilities. Seepkgjs-utils(1)manpagepkgjsβ tries to reproduceyarnpkg(1)commands withpkgjs-*scripts π§
π SEE ALSO π
debhelper(7), pkg-js-autopkgtest(7), uscan(1), add-node-component(1), github-debian-upstream(1), nodepath(1), mjs2cjs(1), pkgjs-ls(1), pkgjs-depends(1), pkgjs-audit(1), pkgjs-utils(1), pkgjs-install(1)
β¨ FEATURES HISTORY β¨
Okay bestie, this is the receipts section π β literally a whole timeline of when each tool showed up and when each feature dropped. Think of it as the "since when does this exist" cheat sheet, iykyk. Every version number here is the minimal version that has the thing, so if your package is older than that, it does not have it, periodt.
π οΈ TOOL β¨
Here's the glow-up timeline for the actual commands. If you're running something older than the number next to it, that tool (or that flag!) isn't in your life yet π
add-node-componentβ0.8.14add-node-component --cmp-treeβ0.9.22debcheck-node-repoβ0.8.14dh_nodejs_autodocsβ0.13.0dh_nodejs_autodocs auto_dispatchβ0.14.5dh_nodejs_build_debug_packageβ0.15.5dh_nodejs_substvarsβ0.14.5dh-make-nodeβ0.9.18getFromNpmCacheβ0.14.32mjs2cjsβ0.12.3mjs2cjs -aβ0.14.14pkgjsβ0.15.21pkgjs-auditβ0.11.2pkgjs-dependsβ0.9.54pkgjs-depends --graphβ0.14.34pkgjs-installβ0.14.20pkgjs-install-minimalβ0.14.27pkgjs-lnβ0.9.76pkgjs-lernaβ0.15.13pkgjs-lsβ0.9.30pkgjs-mainβ0.9.76pkgjs-pjsonβ0.9.76pkgjs-runβ0.14.22pkgjs-utilsβ0.9.75
π FEATURE β¨
And now the vibes timeline π¦ β the behaviours and conventions, with the oldest version that supports each one. Lowkey the most useful part if you're tryna figure out why your build is doing the thing.
additional_componentsβ0.9.11- auto build (grunt) β
0.9.3 - autopkgtest skip β
0.9.30 - auto-install (arch-dep) β
0.9.27 - build order β
0.9.10 dh-sequence-nodejsβ0.9.41- follow
lerna.json#useWorkspacesβ0.14.8 .npmignoresupport β0.9.53- support
lerna.confβ0.12.0 - support workspaces β
0.12.7 debian/nodejs/mainβ0.9.11debian/tests/test_modulesβ0.9.33debian/build_modulesβ0.9.33${nodejs:BuiltUsing}β0.11.8${nodejs:Provides}β0.9.10
β ${nodejs:Version} 0.9.38 β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β ${nodeFoo:Provides} 0.14.5 β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β ordered_components_list 0.15.13 β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β packages_list 0.15.13 β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
π COPYRIGHT AND LICENSE π
okay bestie, legal o'clock, but it's actually a slay π
Copyright Yadd <yadd@debian.org> π«Ά
This library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. β¨
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. π See the GNU General Public License for more details. (yeah, the all-caps is literally screaming at you, that's how licenses do)
On Debian systems, the complete text of version 2 of the GNU General Public License can be found in /usr/share/common-licenses/GPL-2. If not, see GNU licenses. π
ngl if you're shipping this in your own package, read the actual license text fr fr β don't just vibe off this page π
and that's the whole page, bestie!! π you made it all the way through β iconic behavior π
this is the tail end of pkg-js-tools(7), dated June 2024, and it's giving main character energy from the very last line to the very first. go forth and package some JS πβ¨π¦πΈππ§π
π¦ where this page comes from
- debian trixie: pkg-js-tools 0.15.23 Β· GPL-2.0-or-later
- ubuntu questing: pkg-js-tools 0.16.0
- ubuntu resolute: pkg-js-tools 0.17.1 Β· GPL-2.0-or-later
- ubuntu stonking: pkg-js-tools 0.17.8 Β· GPL-2.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms