Giter VIP home page Giter VIP logo

amdefine's People

Contributors

benatkin avatar graingert avatar jrburke avatar pdehaan avatar stasm avatar vojtajina avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

amdefine's Issues

using `global`

Just curious. Have you considered using global to define either define or override require globally?

I meant doing something like this in amdefine:

global.define = function (cb) { ... }

This way users won't need to add conditional amdefine require at top of modules.

Ugly warning when installing via NPM

Seems like the latest version is not yet submitted to NPM. I get an ugly warning:

>npm install amdefine
npm http GET https://registry.npmjs.org/amdefine
npm http 200 https://registry.npmjs.org/amdefine
npm http GET https://registry.npmjs.org/amdefine/-/amdefine-0.0.2.tgz
npm http 200 https://registry.npmjs.org/amdefine/-/amdefine-0.0.2.tgz
npm WARN package.json [email protected] No README.md file found!
[email protected] node_modules\amdefine

not compatible with jQuery > 3.0.0

Hey, I could be wrong but apparently jquery no longer allows .load(), and it must be .on('load', function()...), I think webpack uses amdefine as a dependency, was wondering if there is some sort of workaround, or if I must use an older version of jQuery?

global redefinition of define

I was hoping to be able to set up something like this at the starting point of my script:

global.define = require('amdefine')(module);

so that I could avoid the boilerplate within each module file. I know this doesn't work since the module object is not the right one, but is there some way in which this could be overcome?

Thanks!

superfluous var define

how about a build pragma to exclude it?

//>>excludeStart('amdefine', true);
if (typeof define !== 'function') { var define = require('amdefine')(module) }
//>>excludeEnd('amdefine');

Option to use requirejs path resolution logic

This came up from a use case from @chrispitzer:

If you have modules coded to use amdefine and they work in reqiurejs, if they need to run in something like a busterjs test, or anything that has a command line command that just jumps right into node (cannot insert requirejs in the middle), it would be nice to be able to have the same config used in requirejs loading to work in that scenario, since the modules may not be in the node_modules area for node to find.

First idea: amdefine could read an environment variable that specifies a file that has the requirejs config, and it would use that for loading modules before handing off to node's loader if it cannot find it at that config.

`intercept` does not work with `babel-register`

When using with babel-register the intercept hook kills the registration for babel, so no babel compilation happens, resulting in error

of define !== 'function') {var define = require('amdefine')(module)}import ok
                                                                    ^^^^^^
SyntaxError: Unexpected reserved word

does amdefine have a conflict with lodash?

Error: amdefine with no module ID cannot be called more than once per file.
    at runFactory (/mnt/hgfs/papaRomeo8_web/node_modules/amdefine/amdefine.js:159:23)
    at define (/mnt/hgfs/papaRomeo8_web/node_modules/amdefine/amdefine.js:275:13)
    at /mnt/hgfs/papaRomeo8_web/node_modules/lodash/dist/lodash.js:4964:5
    at Object.<anonymous> (/mnt/hgfs/papaRomeo8_web/node_modules/lodash/dist/lodash.js:4983:2)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/mnt/hgfs/papaRomeo8_web/app.coffee:116:10)
    at Object.<anonymous> (/mnt/hgfs/papaRomeo8_web/app.coffee:145:4)
    at Module._compile (module.js:456:26)
    at Object.exports.run (/usr/lib/node_modules/coffee-script/lib/coffee-script/coffee-script.js:124:25)
    at compileScript (/usr/lib/node_modules/coffee-script/lib/coffee-script/command.js:166:29)
    at /usr/lib/node_modules/coffee-script/lib/coffee-script/command.js:141:18
    at fs.js:252:14
    at Object.oncomplete (fs.js:93:15)

I'm using lodash as a utility library and passing it in to a constructor. If I swap out the require to use underscore instead, it loads fine. I'll put up an issue on the lodash hub as well, since I'm not sure who's disagreeing with who here.

"RequireJS in Node" on requirejs.org: outdated info?

I tried using a built-in define() in a recent 0.6.x version of Node the other day and saw that it didn't work. I'm not sure if I did something wrong but I couldn't find updated docs about define so I think it might be that Node changed since 0.4.x.

If this is the case, what http://requirejs.org/docs/node.html says is no longer true:

The situation has improved a bit in Node 0.5.0 and later, which supports the "simplified CommonJS wrapper" version of define().

Thanks!

Consider releasing 1.0.0

I use amdefine for a long time for isomorphic/universal javascript and it works perfectly. Thanks !

Did you consider releasing 1.0.0 ?

Requires an empty object

I have a file called route.coffee

if typeof define != 'function'
  define = require 'amdefine'
  define module


define ( require ) ->


  Backbone  = require 'backbone'
  fs        = require 'fs'
  doT       = require 'dot'

  routes = ( app ) ->

    app.get '/friends', ( req, res ) ->

      friends     = require app.const.P1_MODULES + '/friends/models/friendList'

      layoutTmp   = fs.readFileSync app.const.DEFAULT_LAYOUT, 'utf8'
      regions     = fs.readFileSync __dirname + '/' + app.const.REGIONS, 'utf8'
      layout      = doT.template layoutTmp

      res.send layout { regions: regions };

  return routes

When I require this file it return an empty objecy? I have node version 0.8.14 and amdefine v. 0.0.4

Ugly warning when installing via NPM

Seems like the latest version is not yet submitted to NPM. I get an ugly warning:

>npm install amdefine
npm http GET https://registry.npmjs.org/amdefine
npm http 200 https://registry.npmjs.org/amdefine
npm http GET https://registry.npmjs.org/amdefine/-/amdefine-0.0.2.tgz
npm http 200 https://registry.npmjs.org/amdefine/-/amdefine-0.0.2.tgz
npm WARN package.json [email protected] No README.md file found!
[email protected] node_modules\amdefine

Node 0.4.7 support

Trying to deploy an app to heroku which is using amdefine, but it fails since module.require is not defined. This was added in node 0.5 I think. Is there any plans to make amdefine support older versions of node to overcome this issue?

Got it working by assigning the global require function to the module object. It feels super hacky and I am not sure what consequences it may have...

Named module support

Is amdefine intended to work with named AMD modules? It seems to work perfectly with anonymous modules, but if I name my modules, instead of getting the module when I require it, I get undefined. Any suggestions?

Loading requireJS plugins with parameters

Hi!

Is it possible to create requireJS plugins with amdefine? The plugin works well in the browser... It seems to be using a simple commonJS require - instead of requireJS require - which is looking for file names only.

I'm using this code in node.js (with jasmine-node):

if (typeof define !== 'function') { var define = require('amdefine')(module, require) }
require("./validation"); //works
require("./validation!./basicTests"); //does not work, but the plugin and path is ok...

stack:

   Message:
     Error: Cannot find module './validation!./basicTests'
   Stacktrace:
     Error: Cannot find module './validation!./basicTests'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:362:17)
    at require (module.js:378:17)
    at null.<anonymous> (D:\creation\software developer\projects\dev\document root\src\validation.plugin.spec.js:9:17)
    at jasmine.Env.describe (D:\creation\software developer\libs\jasmine-node\lib\jasmine-node/jasmine-2.0.0.rc1.js:791:21)
    at describe (D:\creation\software developer\libs\jasmine-node\lib\jasmine-node/jasmine-2.0.0.rc1.js:575:27)
    at Object.<anonymous> (D:\creation\software developer\projects\dev\document root\src\validation.plugin.spec.js:7:1)
    at Module._compile (module.js:449:26)
    at Object.Module._extensions..js (module.js:467:10)

jshint issue

When I use the following code as suggested, jshint throws error on me:

if (typeof define !== 'function') { var define = require('amdefine')(module) }

I found the solution to be simply insert an in-line override for jshint like following:

if (typeof define !== 'function') {
  /*jshint latedef:false */
  var define = require('amdefine')(module);
}

this will only affect this "if" statement, the rest of your code will still use your global setting.

So this is not really an issue, but I thought it is a good idea to share with others here.

Allow built files but just expose the modules locally

So allow named define calls, but just have them as locally available modules. This would allow a built file with multple inlined modules to work as a unit. Those named modules would not be visible to the outside of the module.

with no module ID cannot be called more than once per file.

I got the error when requiring a file. In the file I call the require it is defined without a module ID and it require a module defined without module ID.

You can require files/modules without defining module IDs on the browser, why isn't it possible in node?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.