Building Distribution For D3 Module (d3-dsv)

I want to build the the d3-dsv module so that I have the output folder “dist”. I cannot find any instructions, either within the project itself, or elsewhere on the requirements needed for building as well as the steps. So I tried this:

jlpoole@ryzdesk /usr/local/src/d3-dsv $ git status
On branch main
Your branch is up to date with 'origin/main'.

nothing to commit, working tree clean
jlpoole@ryzdesk /usr/local/src/d3-dsv $ date; git --no-pager log -1
Tue Aug 13 08:03:32 AM PDT 2024
commit a2facce660bb4895b56c62a655d0f252efc3d99f (HEAD -> main, origin/main, origin/HEAD)
Author: Philippe Rivière <fil@rezo.net>
Date:   Fri Oct 6 17:02:43 2023 +0200

restructure README (#100)

https://github.com/d3/d3/issues/3775
jlpoole@ryzdesk /usr/local/src/d3-dsv $ node rollup.config.js
node:internal/modules/esm/assert:88
throw new ERR_IMPORT_ATTRIBUTE_MISSING(url, 'type', validType);
^

TypeError [ERR_IMPORT_ATTRIBUTE_MISSING]: Module "file:///usr/local/src/d3-dsv/package.json" needs an import attribute of "type: json"
at validateAttributes (node:internal/modules/esm/assert:88:15)
at defaultLoad (node:internal/modules/esm/load:143:3)
at async ModuleLoader.load (node:internal/modules/esm/loader:570:7)
at async ModuleLoader.moduleProvider (node:internal/modules/esm/loader:445:45) {
code: 'ERR_IMPORT_ATTRIBUTE_MISSING'
}

Node.js v22.5.1
jlpoole@ryzdesk /usr/local/src/d3-dsv $ git config --get remote.origin.url
https://github.com/d3/d3-dsv.git
jlpoole@ryzdesk /usr/local/src/d3-dsv $

I’d like to build various modules and would like to know what the formulaic approach might be. Could the above error be a result of using a newer release of Node, e.g. 22.5.1?

rollup.config.js is not intended as an executable script. Did you try running yarn prepublishOnly ?

@mootari - your suggestion worked. Thank you.

yarn is a requirement, then. I am unfamiliar with yarn; nonetheless, I relied upon your suggestion. (Gentoo users, the package to install is: sys-apps/yarn).

 jlpoole@ryzdesk /usr/local/src/d3-dsv $ yarn prepublishOnly
yarn run v1.22.22
warning ../package.json: No license field
$ rm -rf dist && yarn test && rollup -c
warning ../package.json: No license field
$ TZ=America/Los_Angeles mocha 'test/**/*-test.js' && eslint src test


? autoType(object) mutates in-place
? autoType(object) detects numbers
? autoType(object) detects NaN
? autoType(object) detects dates
? autoType(object) detects extended years
? autoType(object) detects date-times
? autoType(object) detects booleans
? autoType(object) detects null
? autoType(object) detects strings
? autoType(object) ignores leading and trailing whitespace
? autoType(array) mutates in-place
? autoType(array) can take an array
? csvParse(string) returns the expected objects
? csvParse(string) does not strip whitespace
? csvParse(string) treats empty fields as the empty string
? csvParse(string) treats a trailing empty field as the empty string
? csvParse(string) treats a trailing empty field on the last line as the empty string
? csvParse(string) treats quoted empty strings as the empty string
? csvParse(string) allows the last field to have unterminated quotes
? csvParse(string) ignores a blank last line
? csvParse(string) treats a blank non-last line as a single-column empty string
? csvParse(string) returns empty strings for missing columns
? csvParse(string) does not ignore a whitespace-only last line
? csvParse(string) parses quoted values
? csvParse(string) parses quoted values with quotes
? csvParse(string) parses quoted values with newlines
? csvParse(string) observes Unix, Mac and DOS newlines
? csvParse(string) returns columns in the input order
? csvParse(string) passes the csv-spectrum test suite
? csvParse(string, row) returns the expected converted objects
? csvParse(string, row) skips rows if row returns null or undefined
? csvParse(string, row) calls row(d, i) for each row d, in order
? csvParseRows(string) returns the expected array of array of string
? csvParseRows(string) does not strip whitespace
? csvParseRows(string) treats empty fields as the empty string
? csvParseRows(string) treats a trailing empty field as the empty string
? csvParseRows(string) treats a trailing empty field on the last line as the empty string
? csvParseRows(string) treats quoted empty strings as the empty string
? csvParseRows(string) allows the last field to have unterminated quotes
? csvParseRows(string) ignores a blank last line
? csvParseRows(string) treats a blank non-last line as a single-column empty string
? csvParseRows(string) can return rows of varying length
? csvParseRows(string) does not ignore a whitespace-only last line
? csvParseRows(string) parses quoted values
? csvParseRows(string) parses quoted values with quotes
? csvParseRows(string) parses quoted values with newlines
? csvParseRows(string) parses Unix, Mac and DOS newlines
? csvParseRows("") returns the empty array
? csvParseRows("
") returns an array of one empty string
? csvParseRows("

") returns an array of two empty strings
? csvParseRows(string, row) returns the expected converted array of array of string
? csvParseRows(string, row) skips rows if row returns null or undefined
? csvParseRows(string, row) invokes row(d, i) for each row d, in order
? csvFormat(array) takes an array of objects as input
? csvFormat(array) converts dates to ISO 8601
? csvFormat(array) escapes field names and values containing delimiters
? csvFormat(array) computes the union of all fields
? csvFormat(array) orders fields by first-seen
? csvFormat(array, columns) observes the specified array of column names
? csvFormat(array, columns) coerces column names to strings
? csvFormat(array, columns) coerces field values to strings
? csvFormatBody(array) omits the header row
? csvFormatBody(array, columns) omits the header row
? csvFormatRows(array) takes an array of array of string as input
? csvFormatRows(array) separates lines using Unix newline
? csvFormatRows(array) converts dates to ISO 8601
? csvFormatRows(array) does not strip whitespace
? csvFormatRows(array) does not quote simple values
? csvFormatRows(array) escapes double quotes
? csvFormatRows(array) escapes Unix newlines
? csvFormatRows(array) escapes Windows newlines
? csvFormatRows(array) escapes values containing delimiters
? csvFormatRow(array) takes a single array of string as input
? dsv("|").parse(string) returns the expected objects
? dsv("|").parse(string) does not strip whitespace
? dsv("|").parse(string) parses quoted values
? dsv("|").parse(string) parses quoted values with quotes
? dsv("|").parse(string) parses quoted values with newlines
? dsv("|").parse(string) observes Unix, Mac and DOS newlines
? dsv("|").parse(string, row) returns the expected converted objects
? dsv("|").parse(string, row) skips rows if row returns null or undefined
? dsv("|").parse(string, row) invokes row(d, i, columns) for each row d, in order
? dsv("|").parseRows(string) returns the expected array of array of string
? dsv("|").parseRows(string) parses quoted values
? dsv("|").parseRows(string) parses quoted values with quotes
? dsv("|").parseRows(string) parses quoted values with newlines
? dsv("|").parseRows(string) parses Unix, Mac and DOS newlines
? dsv("|").parseRows(string, row) returns the expected converted array of array of string
? dsv("|").parseRows(string, row) skips rows if row returns null or undefined
? dsv("|").parseRows(string, row) invokes row(d, i) for each row d, in order
? dsv("|").format(array) takes an array of objects as input
? dsv("|").format(array) escapes field names and values containing delimiters
? dsv("|").format(array) computes the union of all fields
? dsv("|").format(array) orders fields by first-seen
? dsv("|").format(array, columns) observes the specified array of column names
? dsv("|").formatRows(array) takes an array of array of string as input
? dsv("|").formatRows(array) separates lines using Unix newline
? dsv("|").formatRows(array) does not strip whitespace
? dsv("|").formatRows(array) does not quote simple values
? dsv("|").formatRows(array) escapes double quotes
? dsv("|").formatRows(array) escapes Unix newlines
? dsv("|").formatRows(array) escapes Windows newlines
? dsv("|").formatRows(array) escapes values containing delimiters
? dsv("|").formatRow(array) takes a single array of string as input
? tsvParse(string) returns the expected objects
? tsvParse(string) does not strip whitespace
? tsvParse(string) parses quoted values
? tsvParse(string) parses quoted values with quotes
? tsvParse(string) parses quoted values with newlines
? tsvParse(string) observes Unix, Mac and DOS newlines
? tsvParse(string, row) returns the expected converted objects
? tsvParse(string, row) skips rows if row returns null or undefined
? tsvParse(string, row) invokes row(d, i) for each row d, in order
? tsvParse(string) accepts numbers as names
? tsvParseRows(string) returns the expected array of array of string
? tsvParseRows(string) parses quoted values
? tsvParseRows(string) parses quoted values with quotes
? tsvParseRows(string) parses quoted values with newlines
? tsvParseRows(string) parses Unix, Mac and DOS newlines
? tsvParseRows(string, row) returns the expected converted array of array of string
? tsvParseRows(string, row) skips rows if row returns null or undefined
? tsvParseRows(string, row) invokes row(d, i) for each row d, in order
? tsvFormat(array) takes an array of objects as input
? tsvFormat(array) escapes field names and values containing delimiters
? tsvFormat(array) computes the union of all fields
? tsvFormat(array) orders fields by first-seen
? tsvFormat(array, columns) observes the specified array of column names
? tsvFormatRows(array) takes an array of array of string as input
? tsvFormatRows(array) separates lines using Unix newline
? tsvFormatRows(array) does not strip whitespace
? tsvFormatRows(array) does not quote simple values
? tsvFormatRows(array) escapes double quotes
? tsvFormatRows(array) escapes Unix newlines
? tsvFormatRows(array) escapes Windows newlines
? tsvFormatRows(array) escapes values containing delimiters
? tsvFormatRow(array) takes a single array of string as input

136 passing (30ms)


src/index.js ? dist/d3-dsv.js...
created dist/d3-dsv.js in 42ms

src/index.js ? dist/d3-dsv.min.js...
created dist/d3-dsv.min.js in 317ms
Done in 1.62s.
jlpoole@ryzdesk /usr/local/src/d3-dsv $

If you don’t want yarn, you could use npm instead (npm run prepublishOnly should work too).

@Fil the script invokes yarn though:

Edit: Apparently one could call $npm_execpath instead to account for different package managers, although there may be bugs in the various implementations.

1 Like

npm run rollup -c then?

So I tried the “npm” approach, it failed. I reverted to the yarn appraoch; it too, failed. Looks like mocha needs to be installed.

jlpoole@ryzdesk /usr/local/src/d3-fetch $ npm run prepublishOnly

> d3-fetch@3.0.1 prepublishOnly
> rm -rf dist && yarn test && rollup -c

yarn run v1.22.22
warning ../package.json: No license field
$ mocha 'test/**/*-test.js' && eslint src test
/bin/sh: line 1: mocha: command not found
error Command failed with exit code 127.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
jlpoole@ryzdesk /usr/local/src/d3-fetch $ ls
LICENSE  package.json  README.md  rollup.config.js  src  test  yarn.lock
jlpoole@ryzdesk /usr/local/src/d3-fetch $ date
Wed Aug 14 02:05:43 PM PDT 2024
jlpoole@ryzdesk /usr/local/src/d3-fetch $ yarn prepublishOnly
yarn run v1.22.22
warning ../package.json: No license field
$ rm -rf dist && yarn test && rollup -c
warning ../package.json: No license field
$ mocha 'test/**/*-test.js' && eslint src test
/bin/sh: line 1: mocha: command not found
error Command failed with exit code 127.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
error Command failed with exit code 127.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
jlpoole@ryzdesk /usr/local/src/d3-fetch $ ls
LICENSE  package.json  README.md  rollup.config.js  src  test  yarn.lock
jlpoole@ryzdesk /usr/local/src/d3-fetch $ eix mocha
* dev-ruby/mocha
Available versions:
(0.14) 0.14.0-r1^t
(1.0)  1.16.0^t 1.16.1^t
(2)    2.0.4^t 2.2.0^t ~2.3.0^t ~2.4.4^t ~2.4.5^t
{doc test RUBY_TARGETS="ruby31 ruby32 ruby33"}
Homepage:            https://mocha.jamesmead.org/
Description:         Mocking and stubbing using a syntax like that of JMock and SchMock

jlpoole@ryzdesk /usr/local/src/d3-fetch $

Based on the above, I’m guessing each module has it’s own recipe?

It seems to me that you might be applying conventions from a different ecosystem to JavaScript. May I ask why you want to build the packages directly instead of installing them via the npm registry?

I like to understand precisely what is going on and to have complete control over what gets installed on my servers.

[Edit] And delivered to my users.

1 Like