UNPKG

8.64 kBJSONView Raw
1{
2 "_args": [
3 [
4 {
5 "raw": "amdefine@>=0.0.4",
6 "scope": null,
7 "escapedName": "amdefine",
8 "name": "amdefine",
9 "rawSpec": ">=0.0.4",
10 "spec": ">=0.0.4",
11 "type": "range"
12 },
13 "/Users/benjamincoe/oss/nyc/node_modules/handlebars/node_modules/source-map"
14 ]
15 ],
16 "_from": "amdefine@>=0.0.4",
17 "_id": "amdefine@1.0.1",
18 "_inCache": true,
19 "_location": "/amdefine",
20 "_nodeVersion": "6.7.0",
21 "_npmOperationalInternal": {
22 "host": "packages-18-east.internal.npmjs.com",
23 "tmp": "tmp/amdefine-1.0.1.tgz_1478062849665_0.19916908955201507"
24 },
25 "_npmUser": {
26 "name": "jrburke",
27 "email": "jrburke@gmail.com"
28 },
29 "_npmVersion": "3.10.3",
30 "_phantomChildren": {},
31 "_requested": {
32 "raw": "amdefine@>=0.0.4",
33 "scope": null,
34 "escapedName": "amdefine",
35 "name": "amdefine",
36 "rawSpec": ">=0.0.4",
37 "spec": ">=0.0.4",
38 "type": "range"
39 },
40 "_requiredBy": [
41 "/handlebars/source-map"
42 ],
43 "_resolved": "https://registry.npmjs.org/amdefine/-/amdefine-1.0.1.tgz",
44 "_shasum": "4a5282ac164729e93619bcfd3ad151f817ce91f5",
45 "_shrinkwrap": null,
46 "_spec": "amdefine@>=0.0.4",
47 "_where": "/Users/benjamincoe/oss/nyc/node_modules/handlebars/node_modules/source-map",
48 "author": {
49 "name": "James Burke",
50 "email": "jrburke@gmail.com",
51 "url": "http://github.com/jrburke"
52 },
53 "bugs": {
54 "url": "https://github.com/jrburke/amdefine/issues"
55 },
56 "dependencies": {},
57 "description": "Provide AMD's define() API for declaring modules in the AMD format",
58 "devDependencies": {},
59 "directories": {},
60 "dist": {
61 "shasum": "4a5282ac164729e93619bcfd3ad151f817ce91f5",
62 "tarball": "https://registry.npmjs.org/amdefine/-/amdefine-1.0.1.tgz"
63 },
64 "engines": {
65 "node": ">=0.4.2"
66 },
67 "gitHead": "e59edc9da24404ec7937098e3992f8fb0e260be7",
68 "homepage": "http://github.com/jrburke/amdefine",
69 "license": "BSD-3-Clause OR MIT",
70 "main": "./amdefine.js",
71 "maintainers": [
72 {
73 "name": "jrburke",
74 "email": "jrburke@gmail.com"
75 }
76 ],
77 "name": "amdefine",
78 "optionalDependencies": {},
79 "readme": "# amdefine\n\nA module that can be used to implement AMD's define() in Node. This allows you\nto code to the AMD API and have the module work in node programs without\nrequiring those other programs to use AMD.\n\n## Usage\n\n**1)** Update your package.json to indicate amdefine as a dependency:\n\n```javascript\n \"dependencies\": {\n \"amdefine\": \">=0.1.0\"\n }\n```\n\nThen run `npm install` to get amdefine into your project.\n\n**2)** At the top of each module that uses define(), place this code:\n\n```javascript\nif (typeof define !== 'function') { var define = require('amdefine')(module) }\n```\n\n**Only use these snippets** when loading amdefine. If you preserve the basic structure,\nwith the braces, it will be stripped out when using the [RequireJS optimizer](#optimizer).\n\nYou can add spaces, line breaks and even require amdefine with a local path, but\nkeep the rest of the structure to get the stripping behavior.\n\nAs you may know, because `if` statements in JavaScript don't have their own scope, the var\ndeclaration in the above snippet is made whether the `if` expression is truthy or not. If\nRequireJS is loaded then the declaration is superfluous because `define` is already already\ndeclared in the same scope in RequireJS. Fortunately JavaScript handles multiple `var`\ndeclarations of the same variable in the same scope gracefully.\n\nIf you want to deliver amdefine.js with your code rather than specifying it as a dependency\nwith npm, then just download the latest release and refer to it using a relative path:\n\n[Latest Version](https://github.com/jrburke/amdefine/raw/latest/amdefine.js)\n\n### amdefine/intercept\n\nConsider this very experimental.\n\nInstead of pasting the piece of text for the amdefine setup of a `define`\nvariable in each module you create or consume, you can use `amdefine/intercept`\ninstead. It will automatically insert the above snippet in each .js file loaded\nby Node.\n\n**Warning**: you should only use this if you are creating an application that\nis consuming AMD style defined()'d modules that are distributed via npm and want\nto run that code in Node.\n\nFor library code where you are not sure if it will be used by others in Node or\nin the browser, then explicitly depending on amdefine and placing the code\nsnippet above is suggested path, instead of using `amdefine/intercept`. The\nintercept module affects all .js files loaded in the Node app, and it is\ninconsiderate to modify global state like that unless you are also controlling\nthe top level app.\n\n#### Why distribute AMD-style modules via npm?\n\nnpm has a lot of weaknesses for front-end use (installed layout is not great,\nshould have better support for the `baseUrl + moduleID + '.js' style of loading,\nsingle file JS installs), but some people want a JS package manager and are\nwilling to live with those constraints. If that is you, but still want to author\nin AMD style modules to get dynamic require([]), better direct source usage and\npowerful loader plugin support in the browser, then this tool can help.\n\n#### amdefine/intercept usage\n\nJust require it in your top level app module (for example index.js, server.js):\n\n```javascript\nrequire('amdefine/intercept');\n```\n\nThe module does not return a value, so no need to assign the result to a local\nvariable.\n\nThen just require() code as you normally would with Node's require(). Any .js\nloaded after the intercept require will have the amdefine check injected in\nthe .js source as it is loaded. It does not modify the source on disk, just\nprepends some content to the text of the module as it is loaded by Node.\n\n#### How amdefine/intercept works\n\nIt overrides the `Module._extensions['.js']` in Node to automatically prepend\nthe amdefine snippet above. So, it will affect any .js file loaded by your\napp.\n\n## define() usage\n\nIt is best if you use the anonymous forms of define() in your module:\n\n```javascript\ndefine(function (require) {\n var dependency = require('dependency');\n});\n```\n\nor\n\n```javascript\ndefine(['dependency'], function (dependency) {\n\n});\n```\n\n## RequireJS optimizer integration. <a name=\"optimizer\"></name>\n\nVersion 1.0.3 of the [RequireJS optimizer](http://requirejs.org/docs/optimization.html)\nwill have support for stripping the `if (typeof define !== 'function')` check\nmentioned above, so you can include this snippet for code that runs in the\nbrowser, but avoid taking the cost of the if() statement once the code is\noptimized for deployment.\n\n## Node 0.4 Support\n\nIf you want to support Node 0.4, then add `require` as the second parameter to amdefine:\n\n```javascript\n//Only if you want Node 0.4. If using 0.5 or later, use the above snippet.\nif (typeof define !== 'function') { var define = require('amdefine')(module, require) }\n```\n\n## Limitations\n\n### Synchronous vs Asynchronous\n\namdefine creates a define() function that is callable by your code. It will\nexecute and trace dependencies and call the factory function *synchronously*,\nto keep the behavior in line with Node's synchronous dependency tracing.\n\nThe exception: calling AMD's callback-style require() from inside a factory\nfunction. The require callback is called on process.nextTick():\n\n```javascript\ndefine(function (require) {\n require(['a'], function(a) {\n //'a' is loaded synchronously, but\n //this callback is called on process.nextTick().\n });\n});\n```\n\n### Loader Plugins\n\nLoader plugins are supported as long as they call their load() callbacks\nsynchronously. So ones that do network requests will not work. However plugins\nlike [text](http://requirejs.org/docs/api.html#text) can load text files locally.\n\nThe plugin API's `load.fromText()` is **not supported** in amdefine, so this means\ntranspiler plugins like the [CoffeeScript loader plugin](https://github.com/jrburke/require-cs)\nwill not work. This may be fixable, but it is a bit complex, and I do not have\nenough node-fu to figure it out yet. See the source for amdefine.js if you want\nto get an idea of the issues involved.\n\n## Tests\n\nTo run the tests, cd to **tests** and run:\n\n```\nnode all.js\nnode all-intercept.js\n```\n\n## License\n\nNew BSD and MIT. Check the LICENSE file for all the details.\n",
80 "readmeFilename": "README.md",
81 "repository": {
82 "type": "git",
83 "url": "git+https://github.com/jrburke/amdefine.git"
84 },
85 "scripts": {},
86 "version": "1.0.1"
87}