New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

nmf-webpack-loader

Package Overview
Dependencies
Maintainers
2
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nmf-webpack-loader - npm Package Compare versions

Comparing version 2.0.2 to 2.0.3

.eslintrc

9

package.json
{
"name": "nmf-webpack-loader",
"version": "2.0.2",
"version": "2.0.3",
"description": "A Webpack loader for Native Client manifests",

@@ -16,4 +16,7 @@ "main": "src/nmf-loader.js",

"devDependencies": {
"file-loader": "^0.11.1",
"webpack": "^2.4.1"
"eslint": "^4.18.1",
"eslint-config-tidal": "^1.1.4",
"file-loader": "^1.1.9",
"webpack": "^4.0.0",
"webpack-cli": "^2.0.9"
},

@@ -20,0 +23,0 @@ "dependencies": {

# nmf-loader - A Webpack loader for Native Client manifests
[![Build Status](https://travis-ci.org/tidal-engineering/nmf-webpack-loader.svg?branch=master)](https://travis-ci.org/tidal-engineering/nmf-webpack-loader)
This loader parses your .nmf file, searches for "url" occurences, copies

@@ -4,0 +6,0 @@ the assets into the output directory, replaces the url with the outputted path,

@@ -11,2 +11,3 @@ const path = require('path');

this.cacheable();
const callback = this.async();

@@ -17,9 +18,9 @@ const context = this;

var query = loaderUtils.getOptions(this);
var configKey = query.config || "nmfLoader";
var options = this.options[configKey] || {};
const query = loaderUtils.getOptions(this);
const configKey = query.config || 'nmfLoader';
const options = query[configKey] || {};
const config = makeConfig(options, query);
function replaceUrl(url) {
function replaceUrl (url) {
return new Promise((resolve, reject) => {

@@ -36,23 +37,24 @@ importFile.call(context, config, url, (err, result) => {

function recursiveReplaceUrls(data) {
if (Array.isArray(data)) {
return Promise.all(data.map(recursiveReplaceUrls)).then(stringified => '[' + stringified.join(',\n') + ']');
} else if (Object.prototype.toString.call(data) === '[object Object]') {
return Promise.all(Object.keys(data).map(key => {
function recursiveReplaceUrls (otherData) {
if (Array.isArray(otherData)) {
return Promise.all(otherData.map(recursiveReplaceUrls)).then(stringified => '[' + stringified.join(',\n') + ']');
} else if (Object.prototype.toString.call(otherData) === '[object Object]') {
return Promise.all(Object.keys(otherData).map(key => {
if (key === 'url') {
return replaceUrl(data[key]).then(replaced => `"url": ${replaced}`);
} else {
return recursiveReplaceUrls(data[key]).then(recursive => JSON.stringify(key) + ': ' + recursive);
return replaceUrl(otherData[key]).then(replaced => `"url": ${replaced}`);
}
return recursiveReplaceUrls(otherData[key]).then(recursive => JSON.stringify(key) + ': ' + recursive);
})).then(stringified => '{' + stringified.join(',\n') + '}');
} else {
return Promise.resolve(JSON.stringify(data));
}
return Promise.resolve(JSON.stringify(otherData));
}
recursiveReplaceUrls(data).then(res => {
const importRuntime = "var runtime = require(" +
loaderUtils.stringifyRequest(this, "!" + require.resolve("./runtime.js")) +
");";
const code = importRuntime + 'module.exports = "data:application/x-pnacl," + JSON.stringify(' +res + ');';
const importRuntime = 'var runtime = require(' +
loaderUtils.stringifyRequest(this, '!' + require.resolve('./runtime.js')) +
');';
const code = importRuntime + 'module.exports = "data:application/x-pnacl," + JSON.stringify(' + res + ');';
callback(null, code);

@@ -65,10 +67,10 @@ }).catch(err => {

// This snippet is borrowed from webpack's file-loader
function makeConfig(options, query) {
function makeConfig (options, query) {
const config = {
publicPath: false,
name: "[hash].[ext]"
name: '[hash].[ext]'
};
// options takes precedence over config
Object.keys(options).forEach(function(attr) {
Object.keys(options).forEach(function (attr) {
config[attr] = options[attr];

@@ -78,11 +80,13 @@ });

// query takes precedence over config and options
Object.keys(query).forEach(function(attr) {
Object.keys(query).forEach(function (attr) {
config[attr] = query[attr];
});
return config;
}
function importFile(config, file, callback) {
function importFile (config, file, callback) {
const moduleRequest = loaderUtils.urlToRequest(file);
const dirname = path.dirname(this.resource);
this.resolve(dirname, moduleRequest, (err, filename) => {

@@ -95,29 +99,21 @@ if (err) {

const _oldResource = this.resource;
this.resource = filename;
const {name, ext} = path.parse(filename);
const { name, ext } = path.parse(filename);
const newName = config.name.replace('[name]', name).replace('.[ext]', ext);
var url = loaderUtils.interpolateName(this, newName, {
context: config.context || this.options.context,
const url = loaderUtils.interpolateName(this, newName, {
context: config.context || this.rootContext || this.options.context,
content: binaryData,
regExp: config.regExp
});
this.resource = _oldResource;
var publicPath = "__webpack_public_path__ + " + JSON.stringify(url);
if (config.publicPath) {
// support functions as publicPath to generate them dynamically
publicPath = JSON.stringify(
typeof config.publicPath === "function"
? config.publicPath(url)
: config.publicPath + url
);
}
this.emitFile(url, binaryData);
const request = 'runtime.absolutePath(require(' + loaderUtils.stringifyRequest(this, moduleRequest) + '))';
callback(null, request);

@@ -124,0 +120,0 @@ }

@@ -11,19 +11,22 @@ const path = require('path');

module: {
rules: [{
test: /\.nmf$/,
use: {
loader: 'nmf-loader',
options: {
name: '[name].[hash:6].[ext]'
rules: [
{
test: /\.nmf$/,
use: {
loader: 'nmf-loader',
options: {
name: '[name].[hash:6].[ext]'
}
}
},
}, {
test: /\.((nexe)|(pexe)|(so))$/,
use: {
loader: 'file-loader',
options: {
name: '[name].[hash:6].[ext]'
{
test: /\.((nexe)|(pexe)|(so))$/,
use: {
loader: 'file-loader',
options: {
name: '[name].[hash:6].[ext]'
}
}
}
}],
],
noParse: [

@@ -36,3 +39,3 @@ /runtime\.js$/

},
target: "web"
target: 'web'
};
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc