electron-protocol-serve
Advanced tools
Comparing version 1.1.0 to 1.2.0-2
# Changelog | ||
## 1.2.0 | ||
- Set environment variable allowing renderer process to set module search path correctly | ||
## 1.1.0 | ||
@@ -4,0 +8,0 @@ |
41
index.js
const { join } = require('path'); | ||
const fs = require('fs'); | ||
const createHandler = require('./lib/handler'); | ||
@@ -20,4 +20,3 @@ function requiredParam(param, errorMessage) { | ||
* @param {String} options.endpoint endpoint of your protocol, defaults to `dist` | ||
* @param {String} options.directoryIndexFile directory index. usally the default, `index.html` | ||
* @param {String} options.indexPath defaults to cwd + directoryIndexFile | ||
* @param {String} options.indexPath defaults to 'index.html' in cwd | ||
* | ||
@@ -32,3 +31,2 @@ * @return {String} name of your protocol | ||
endpoint = 'dist', | ||
directoryIndexFile = 'index.html', | ||
indexPath = undefined, | ||
@@ -40,32 +38,9 @@ }) { | ||
indexPath = indexPath || join(cwd, directoryIndexFile); | ||
indexPath = indexPath || join(cwd, 'index.html'); | ||
const cache = {}; | ||
const prefixLength = name.length + 3 + endpoint.length; | ||
const options = { cwd, name, endpoint, indexPath }; | ||
const handler = createHandler(options); | ||
app.on('ready', () => { | ||
protocol.registerFileProtocol(name, (request, callback) => { | ||
// the request url should start with ' ${name}://${endpoint}', remove that | ||
const [url/* , hash */] = request.url.substr(prefixLength).split('#'); | ||
const urlSegments = url.split('/').filter(segment => segment !== ''); | ||
if (urlSegments.length === 0) { | ||
urlSegments.push(directoryIndexFile); | ||
} | ||
const filepath = join(cwd, ...urlSegments); | ||
// redirect empty requests to index.html | ||
if (!cache[url]) { | ||
try { | ||
fs.accessSync(filepath); | ||
cache[url] = filepath; | ||
} catch (err) { | ||
// | ||
} | ||
} | ||
callback({ path: cache[url] || indexPath }); | ||
}, error => { | ||
protocol.registerFileProtocol(name, handler, error => { | ||
if (error) { | ||
@@ -77,3 +52,7 @@ console.error('Failed to register protocol'); | ||
// Set our ELECTRON_PROTOCOL_SERVE_INDEX environment variable so the renderer | ||
// process can find index.html to set it up as its main module path | ||
handler({ url: `${name}://${endpoint}` }, ({ path }) => process.env.ELECTRON_PROTOCOL_SERVE_INDEX = path); | ||
return name; | ||
}; |
{ | ||
"name": "electron-protocol-serve", | ||
"version": "1.1.0", | ||
"version": "1.2.0-2", | ||
"description": "A file protocol that serves any existing file in a directory and redirects everything not found to index.html.", | ||
@@ -10,8 +10,17 @@ "main": "index.js", | ||
"scripts": { | ||
"test": "npm run mocha && npm run lint", | ||
"mocha": "mocha ./tests/**/*-test.js", | ||
"lint": "eslint ." | ||
}, | ||
"devDependencies": { | ||
"eslint": "^3.17.1" | ||
"bluebird": "^3.5.0", | ||
"chai": "^3.5.0", | ||
"eslint": "^3.17.1", | ||
"lodash": "^4.17.4", | ||
"mocha": "^3.2.0", | ||
"sinon": "^1.17.7" | ||
}, | ||
"dependencies": {} | ||
"dependencies": { | ||
"mock-require": "^2.0.1" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
50684
13
462
1
6
2
9
1
+ Addedmock-require@^2.0.1
+ Addedcaller-id@0.1.0(transitive)
+ Addedmock-require@2.0.2(transitive)
+ Addedstack-trace@0.0.10(transitive)