Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't run as binary #20

Open
jccr opened this issue Jun 23, 2019 · 5 comments
Open

Can't run as binary #20

jccr opened this issue Jun 23, 2019 · 5 comments

Comments

@jccr
Copy link

jccr commented Jun 23, 2019

Same issue as readium/r2-streamer-js#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 <[email protected]>",
  "license": "MIT",
  "dependencies": {
    "r2-shared-js": "^1.0.13"
  }
}
@jccr
Copy link
Author

jccr commented Jun 23, 2019

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 <[email protected]>",
  "license": "MIT",
  "dependencies": {
    "r2-shared-js": "^1.0.13"
  }
}

But I hit another snag:

> [email protected] 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
Copy link
Member

Refs:

"bin": {
"r2-shared-js-cli": "dist/es6-es2015/src/_utils/cli.js"
},

==>

https://unpkg.com/[email protected]/dist/es6-es2015/src/_utils/cli.js

Also note:

r2-shared-js/package.json

Lines 130 to 132 in 26bde38

"cli": "node \"./dist/es8-es2017/src/_utils/cli.js\"",
"cli-debug": "cross-env DEBUG=r2:* npm run cli",
"cli-debug-x": "cross-env DEBUG=* npm run cli",

Usage instructions:

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

@danielweck
Copy link
Member

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/[email protected]/dist/es8-es2017/src/models/publication-link.js

@jccr
Copy link
Author

jccr commented Jul 15, 2019

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

@jccr
Copy link
Author

jccr commented Jul 16, 2019

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants