browserify-transform-machinepack
Advanced tools
Comparing version 1.0.2 to 1.0.3
46
index.js
@@ -5,3 +5,4 @@ /** | ||
var Path = require('path'); | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
var util = require('util'); | ||
@@ -13,2 +14,3 @@ var _ = require('lodash'); | ||
module.exports = transformTools.makeStringTransform('machinepack', {}, function (code, transformOptions, done) { | ||
// console.log('Running transform on `%s`...',transformOptions.file); | ||
if(!transformOptions.config) { | ||
@@ -19,10 +21,42 @@ return done(new Error('Could not find `machinepack` object in package.json file.')); | ||
var filePath = transformOptions.file; | ||
var packPath = transformOptions.configData.configDir; | ||
var packMetadata = transformOptions.config; | ||
var isTopLevelPackIndex = _.endsWith(filePath, Path.join(packPath, 'index.js')); | ||
// EXTREMELY IMPORTANT: | ||
// All of this info has to do with the TOP-LEVEL machinepack | ||
// (i.e. if the current file being transformed is the main index.js of | ||
// ANOTHER pack required by the top-level pack, then `packMetadata` etc | ||
// will still be referring to the top-level pack!!) | ||
// var packPath = transformOptions.configData.configDir; | ||
// var packMetadata = transformOptions.config; | ||
// var isTopLevelPackIndex = _.endsWith(filePath, path.join(packPath, 'index.js')); | ||
// console.log('skipping... our check failed:'); | ||
// console.log('_.endsWith(filePath, path.join(packPath, \'index.js\'))'); | ||
// console.log('_.endsWith(%s, %s)', filePath, path.join(packPath, 'index.js')); | ||
// console.log(isTopLevelPackIndex); | ||
// console.log(); | ||
// console.log(); | ||
// So now, we need to determine whether we are looking at the `index.js` file | ||
// of ANY machinepack (i.e. not THE machinepack). We'll determine the path pack, | ||
// as well as load the pack metadata. | ||
var packMetadata; | ||
var packPath; | ||
try { | ||
packMetadata = JSON.parse(fs.readFileSync(path.resolve(filePath, '../package.json'), 'utf8')).machinepack; | ||
// If we made it here, looks like this is a pack. | ||
if (packMetadata.friendlyName){ | ||
// So we'll determine the path to the pack directory. | ||
packPath = path.resolve(filePath, '../'); | ||
} | ||
} | ||
catch (e) {} | ||
// console.log('PACKAGE.JSON PATH:',path.resolve(filePath, '../package.json')); | ||
// console.log('PACK METADATA:',packMetadata); | ||
// console.log('PACK PATH:',packPath); | ||
var isThisFilePackIndex = _.isString(packPath) && _.endsWith(filePath, path.join(packPath, 'index.js')); | ||
// If this is not the `index.js` file of a machinepack, leave | ||
// the code alone. | ||
if (!isTopLevelPackIndex) { | ||
if (!isThisFilePackIndex) { | ||
return done(null, code); | ||
@@ -36,3 +70,3 @@ } | ||
var shimCode = _.reduce(packMetadata.machines, function (memo, machineIdentity){ | ||
var line = util.format('module.exports[Machine.getMethodName(\'%s\')] = Machine.build( require(\'%s\') );\n', machineIdentity, './'+Path.join(packMetadata.machineDir,machineIdentity)); | ||
var line = util.format('module.exports[Machine.getMethodName(\'%s\')] = Machine.build( require(\'%s\') );\n', machineIdentity, './'+path.join(packMetadata.machineDir,machineIdentity)); | ||
memo += line; | ||
@@ -39,0 +73,0 @@ return memo; |
{ | ||
"name": "browserify-transform-machinepack", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "A browserify transform that makes machinepacks work when they are required from a browserified module (or each other).", | ||
@@ -5,0 +5,0 @@ "scripts": {}, |
@@ -11,5 +11,37 @@ <h1> | ||
### Usage | ||
To make a machinepack work with browserify, first run add this package as a depenendency: | ||
``` | ||
npm install browserify-transform-machinepack --save | ||
``` | ||
Then add the following to the package.json file of your machinepack: | ||
```js | ||
"browserify": { | ||
"transform": [ | ||
"browserify-transform-machinepack" | ||
] | ||
} | ||
``` | ||
Finally, commit, tag a new version of your pack (e.g. `npm version patch`), push to your repo, and publish to npm. | ||
That's it! Now you can require this machinepack from other browserified packages and scripts, as well as compile it directly. For convenience during testing, a command that does the latter (`mp browserify`) is available in the machinepack CLI tool. | ||
If you have any questions about this module, or issues using it, please [respond to the relevant post in the node-machine Google Group](https://groups.google.com/forum/#!topic/node-machine/TK3JYnCZ8Nw). | ||
## License | ||
MIT © 2015 Mike McNeil, The Treeline Company | ||
MIT | ||
Copyright © 2015 Mike McNeil, The Treeline Company | ||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
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
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
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
6821
71
47
1