define rewriting ignores my dependencies
- Dominant language
- JavaScript
- Stars
- 402
- Forks
- 134
- PR merge metrics
- No merged PRs in 30d
Description
**I'm submitting a feature request**
* **Library Version:**
0.30.1
**Please tell us about your environment:**
* **Operating System:**
Windows 10
* **Node Version:**
8.1.2
* **NPM Version:**
5.0.3
* **Browser:**
all
* **Language:**
all
**Current behavior:**
I am trying to incorporate pikaday into an aurelia cli project, and I specify the following in my aurelia.json:
```json
{
"name": "moment",
"main": "./moment.js",
"path": "../node_modules/moment",
"resources": [],
"export": "moment"
},
{
"name": "pikaday",
"main": "pikaday.js",
"path": "../node_modules/pikaday",
"resources": [
"css/pikaday.css"
],
"deps": ["moment"]
},
```
pikaday does some obnoxious dynamic stuff trying to figure out what module system it should use:
```javascript
var moment;
if (typeof exports === 'object') {
// CommonJS module
// Load moment.js as an optional dependency
try { moment = require('moment'); } catch (e) {}
module.exports = factory(moment);
} else if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(function (req)
{
// Load moment.js as an optional dependency
var id = 'moment';
try { moment = req(id); } catch (e) {}
return factory(moment);
});
} else {
root.Pikaday = factory(root.moment);
}
```
my project is set up with systemjs, and pikaday executes the AMD block, however require("moment") fails with
Error: Module moment not declared as a System.registerDynamic dependency of (pikaday)
The thing is, the define call is being rewritten by something in the bundler to
```javascript
define('pikaday/pikaday',['require'],function (req) {
...
}
```
if I manually add moment to the dependency list, eg
```javascript
define('pikaday/pikaday',['require', 'moment'],function (req) {
...
}
```
pikaday works and integrates with moment.
Also, if I manually remove the define call, the bundler will surround all of pikaday with
```js
define('pikaday/pikaday',['require','exports','module','moment'],function (require, exports, module) {/*!
```
**Expected/desired behavior:**
I would like the define-rewriting behavior to include dependencies that I manually specify in aurelia.json to be consistent with the wrapping behavior
* **What is the motivation / use case for changing the behavior?**
integrating pikaday with moment in an aurelia-cli project
Contributor guide
Assessment
This issue has not been assessed yet.