readium / r2-shared-js

Shared models for Readium Desktop
BSD 3-Clause "New" or "Revised" License
11 stars 13 forks source link

Can't run as binary #20

Open jccr opened 5 years ago

jccr commented 5 years ago

Same issue as https://github.com/readium/r2-streamer-js/issues/44

My use case here is to batch process EPUB publication files from within the NPM package.json scripting mechanism.

Example:

{
  "name": "rwpm-batch-convert",
  "version": "1.0.0",
  "description": "Convert publications to include Readium Web Publication Manifest files.",
  "main": "index.js",
  "scripts": {
    "test": "r2-shared-js-cli [some input here]"
  },
  "author": "Juan Corona <juanc@evidentpoint.com>",
  "license": "MIT",
  "dependencies": {
    "r2-shared-js": "^1.0.13"
  }
}
jccr commented 5 years ago

Tried patching it in my little test project:

{
  "name": "rwpm-batch-process",
  "version": "1.0.0",
  "description": "Process publications to include Readium Web Publication Manifest files.",
  "main": "index.js",
  "scripts": {
    "postinstall": "sed -n '/^#!/p;q' node_modules/.bin/r2-shared-js-cli && sed -i '1s;^;#!/usr/bin/env node\\'$'\n;' node_modules/.bin/r2-shared-js-cli",
    "test": "r2-shared-js-cli"
  },
  "author": "Juan Corona <juanc@evidentpoint.com>",
  "license": "MIT",
  "dependencies": {
    "r2-shared-js": "^1.0.13"
  }
}

But I hit another snag:

> rwpm-batch-process@1.0.0 test /home/juanc/Projects/_experiments/rwpm-batch-process
> r2-shared-js-cli

internal/modules/cjs/loader.js:605
    throw err;
    ^

Error: Cannot find module '../models/publication-link'

When the script sourced from node_modules/.bin/r2-shared-js-cli runs, the require statements don't seem to map to the paths.

const publication_link_1 = require("../models/publication-link");
danielweck commented 5 years ago

Refs:

https://github.com/readium/r2-shared-js/blob/26bde386bf631192e33b1c83375cdefc43b96100/package.json#L86-L88

==>

https://unpkg.com/r2-shared-js@1.0.13/dist/es6-es2015/src/_utils/cli.js

Also note:

https://github.com/readium/r2-shared-js/blob/26bde386bf631192e33b1c83375cdefc43b96100/package.json#L130-L132

Usage instructions:

https://github.com/readium/r2-shared-js/blob/develop/README.md#developer-quick-start

danielweck commented 5 years ago

Instead of invoking node_modules/.bin/r2-shared-js-cli I would call directly: dist/es6-es2015/src/_utils/cli.js (or even better: dist/es8-es2017/src/_utils/cli.js).

Error: Cannot find module '../models/publication-link'

Strange! It's definitely there:

https://unpkg.com/r2-shared-js@1.0.13/dist/es8-es2017/src/models/publication-link.js

jccr commented 5 years ago

@danielweck Not sure what was happening... Your comments make sense to me. Ran it again and it worked. :confused:

jccr commented 5 years ago

Found out I got that Error: Cannot find module '../models/publication-link' because the symlink in node_modules/.bin/r2-shared-js-cli was broken, and wasn't pointing to the link but a copied regular file. at the time of my testing. (I made this happen, so no actual issue here)