Skip to content

Commit

Permalink
fix: 修复puppeteer引用路径不正确的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
axetroy committed Oct 30, 2017
1 parent cd094e3 commit 3fd2899
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 10 deletions.
3 changes: 2 additions & 1 deletion config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module.exports = {
paths: {
root: __dirname,
app: path.join(__dirname, 'app'),
bin: path.join(__dirname, 'bin')
bin: path.join(__dirname, 'bin'),
puppeteer: path.dirname(require.resolve('puppeteer'))
}
};
10 changes: 5 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ process.on('unhandledRejection', (reason, p) => {
console.error('Unhandled Rejection at:', p, 'reason:', reason);
});

const puppeteerModulePath = path.join(config.paths.root, 'node_modules', 'puppeteer');
const localChromiumPath = path.join(puppeteerModulePath, '.local-chromium');

// 运行时检查是已运行
const isChromiumExist = checkIsChromiumExist();

if (isChromiumExist === false) {
console.error(
`Please make sure ${chalk.green('chromium')} have install at ${chalk.yellow(localChromiumPath)}`
`Please make sure ${chalk.green('chromium')} have install at ${chalk.yellow(path.join(config.paths.puppeteer, '.local-chromium'))}`
);
console.error(
`Try to reinstall: ${chalk.green('node ' + config.paths.puppeteer + '/install.js')}`
);
console.error(`Try to reinstall: ${chalk.green('node ' + puppeteerModulePath + '/install.js')}`);
process.exit(1);
}

Expand Down
3 changes: 1 addition & 2 deletions isChromiumExist.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ const config = require('./config');
* @returns {boolean}
*/
module.exports = function() {
const puppeteerModulePath = path.join(config.paths.root, 'node_modules', 'puppeteer');
const localChromiumPath = path.join(puppeteerModulePath, '.local-chromium');
const localChromiumPath = path.join(config.paths.puppeteer, '.local-chromium');

let isExisted = false;

Expand Down
3 changes: 1 addition & 2 deletions scripts/chromium-checker
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ console.info(`${chalk.blue('Checking Chromium')}...`);
const path = require('path');
const config = require('../config');
const isChromiumExist = require('../isChromiumExist');
const puppeteerModulePath = path.join(config.paths.root, 'node_modules', 'puppeteer');

const existed = isChromiumExist();

Expand All @@ -23,5 +22,5 @@ if (existed) {
console.info(`${chalk.red('Chromium not exist...')}`);
console.info(`${chalk.blue('Chromium installing...')}`);
// run install script
require(path.join(puppeteerModulePath, 'install.js'));
require(path.join(config.paths.puppeteer, 'install.js'));
}

0 comments on commit 3fd2899

Please sign in to comment.