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 make it work #73

Closed
kingio opened this issue Sep 13, 2017 · 8 comments · Fixed by #76
Closed

Can't make it work #73

kingio opened this issue Sep 13, 2017 · 8 comments · Fixed by #76
Labels

Comments

@kingio
Copy link

kingio commented Sep 13, 2017

Platform: Windows 10 - 64b
Node: v6.11.1
npm: 3.10.10
crx: 3.2.1

  1. I've run: node ..\node_modules\crx\bin\crx.js pack -o build.crx and it generated the build.crx + key.pem
  2. I've tried running:
const fs = require("fs");
const ChromeExtension = require("crx");
const crx = new ChromeExtension({
  codebase: "https://domain.com/build.crx",
  privateKey: fs.readFileSync("./build/key.pem")
});

crx.load('./build')
  .then(crx => crx.pack())
  .then(crxBuffer => {
    console.log("writting");
    fs.writeFile('builx.crx', crxBuffer);

    const xmlBuffer = crx.generateUpdateXML();
    fs.writeFile('update.xml', xmlBuffer);
  });

And doesn't output anything.
Also tried moving generateUpdateXML outside the crx.load and throws: throw new Error('Public key is neither set, nor given');
I've checked and pack command didn't save any publickey.
¿What can i do to make this package work?

@thom4parisot
Copy link
Owner

Hey @kingio,

I'm sorry to read you have some hard time making it work. Let's try to fix this together 🙂

I see you try to load the content of the ./build directory. Is it the one which contains your extension manifest.json file? Or is it the location you want to store the compiled extension to?
If you aim load() at the directory which contains your extension, it should work.

generateUpdateXML can be called only after load happened so it has to be somewhere in the chain of promises. It is not the source of your problem I suppose.

If the source code of your extension is on GitHub and the pointers I just wrote did not help, feel free to share your repo so as we can have a look at it.

@kingio
Copy link
Author

kingio commented Sep 19, 2017

Yes, manifest was inside build directory.
I ended hardcoding the public key in your code to build the crx.

@reyoucat
Copy link

archive
        .glob(selfie.src, {
          cwd: selfie.path,
          matchBase: true,
          ignore: ['node_modules/**', '*.pem', '.git', '*.crx']
        })
        .finalize();

maybe, ignoring the folder will resolve it. (node_modules/**)

@msakamoto-sf
Copy link

msakamoto-sf commented Dec 12, 2017

@kingio me too, same problem.

debugging with vscode, I found program abort at this line:
https://github.com/oncletom/crx/blob/master/src/crx.js#L96

 load: function (path) {
    var selfie = this;

    return resolve(path || selfie.rootDirectory)
      .then(function(metadata){
        selfie.path = metadata.path;
        selfie.src = metadata.src;

        selfie.manifest = require(join(selfie.path, "manifest.json"));
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

I tried this tiny script: ( ./dist/chrome/manifest.json existed.)

const manifest = require(path.join('./dist/chrome/', 'manifest.json'))

this result:

module.js:538
    throw err;
    ^

Error: Cannot find module 'dist\chrome\manifest.json'
    at Function.Module._resolveFilename (module.js:536:15)
    at Function.Module._load (module.js:466:25)
    at Module.require (module.js:579:17)
    at require (internal/module.js:11:18)
...

but const manifest = require('./dist/chrome/manifest.json') works correctly (success to json read).

@msakamoto-sf
Copy link

I think this problem re-produce only at windows platform.

@msakamoto-sf
Copy link

path.join('./dist/chrome/', 'manifest.json') on windows generates dist\chrome\manifest.json.
->
const manifest = require('./dist/chrome/manifest.json') successed,
<>
const manifest = require('dist\\chrome\\manifest.json') failed.

this may be node.js require() bug on windows platform.

@msakamoto-sf
Copy link

This works on Windows10 Pro 64bit, node.js v8.9.1

function monkeyPatchedResolve (path) {
  return new Promise(function (resolve, reject) {
    return resolve({
      path: path,
      src: '**'
    })
  })
}

crx.load = (path) => {
  var selfie = crx
  return monkeyPatchedResolve(path || selfie.rootDirectory)
    .then(function (metadata) {
      selfie.path = metadata.path
      selfie.src = metadata.src
      selfie.manifest = require(selfie.path + '/manifest.json')
      selfie.loaded = true
      return selfie
    })
}
crx.load('./dist/chrome') // WARNING : './' NEEDED !!
  .then(() => {
    return crx.loadContents()
  })
  .then((zipBuffer) => {
    fs.writeFile(`build/my-ext.chrome.zip`)
    return crx.pack(zipBuffer)
  })
  .then(crxBuffer => {
    const updateXML = crx.generateUpdateXML()
    fs.writeFile(`build/chrome-update.xml`, updateXML)
    fs.writeFile(`build/my-ext.crx`, crxBuffer)
    console.log('chrome packaging done.')
  })

Good Luck !!

@thom4parisot
Copy link
Owner

Sorry for being late in the game.

I have setup a Windows build in the PR #76. But I struggle to reproduce the problem on any version of Node on Windows. Could it be related to the version of Windows too? We can build on Windows Server 2012 R2 or Windows Server 2016.

Let me know, I'd be happy to see this one fixed.

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

Successfully merging a pull request may close this issue.

4 participants