ember-cli-moment-shim
Advanced tools
Comparing version 3.5.0 to 3.5.1
200
index.js
@@ -8,3 +8,2 @@ /* globals require, module, process */ | ||
const mergeTrees = require('broccoli-merge-trees'); | ||
const defaults = require('lodash.defaults'); | ||
const funnel = require('broccoli-funnel'); | ||
@@ -24,15 +23,36 @@ const existsSync = require('exists-sync'); | ||
this._super.included.apply(this, arguments); | ||
this._options = this.getOptions(); | ||
this.momentNode = new UnwatchedDir(this._options.momentPath); | ||
this.importDependencies(); | ||
this.context = this.buildContext(); | ||
this.momentNode = new UnwatchedDir(this.context.momentPath); | ||
this.importDependencies(this.context); | ||
}, | ||
updateFastBootManifest(manifest) { | ||
let target = 'fastboot-moment.js'; | ||
findModulePath(moduleName) { | ||
try { | ||
let resolve = require('resolve'); | ||
if (this._options.includeTimezone) { | ||
target = 'fastboot-moment-timezone.js' | ||
return path.dirname( | ||
resolve.sync(moduleName, { basedir: this.project.root }) | ||
); | ||
} catch (_) { | ||
try { | ||
return path.dirname(require.resolve(moduleName)); | ||
} catch (e) { | ||
if (e.code === 'MODULE_NOT_FOUND') { | ||
this.ui.writeLine( | ||
`ember-cli-moment-shim: ${moduleName} not installed. Try resolving via "npm install ${moduleName}".` | ||
); | ||
return; | ||
} | ||
throw e; | ||
} | ||
} | ||
}, | ||
manifest.vendorFiles.push('moment/' + target); | ||
updateFastBootManifest(manifest) { | ||
if (this.context.includeTimezone) { | ||
manifest.vendorFiles.push('moment/fastboot-moment-timezone.js'); | ||
} else { | ||
manifest.vendorFiles.push('moment/fastboot-moment.js'); | ||
} | ||
@@ -42,6 +62,4 @@ return manifest; | ||
importDependencies() { | ||
let options = this._options; | ||
if (options.includeTimezone) { | ||
importDependencies(context) { | ||
if (context.includeTimezone) { | ||
this.import( | ||
@@ -56,3 +74,3 @@ { | ||
if (typeof options.includeLocales === 'boolean' && options.includeLocales) { | ||
if (typeof context.includeLocales === 'boolean' && context.includeLocales) { | ||
this.import( | ||
@@ -66,5 +84,7 @@ { | ||
} else { | ||
if (Array.isArray(options.includeLocales)) { | ||
options.includeLocales.forEach(locale => { | ||
this.import('vendor/moment/locales/' + locale + '.js', { prepend: true }); | ||
if (this.hasLocales(context)) { | ||
context.includeLocales.forEach(locale => { | ||
this.import('vendor/moment/locales/' + locale + '.js', { | ||
prepend: true | ||
}); | ||
}); | ||
@@ -83,28 +103,42 @@ } | ||
getOptions() { | ||
let projectConfig = (this.project.config(process.env.EMBER_ENV) || {}).moment || {}; | ||
let momentPath = path.dirname(require.resolve('moment')); | ||
let config = defaults(projectConfig, { | ||
momentPath: momentPath, | ||
includeTimezone: null, | ||
includeLocales: [] | ||
}); | ||
writeLine(msg = '', color = 'yellow') { | ||
this.ui.writeLine(chalk[color](`ember-cli-moment-shim: ${msg}`)); | ||
}, | ||
if (Array.isArray(config.includeLocales)) { | ||
config.includeLocales = config.includeLocales | ||
hasLocales(context) { | ||
return Array.isArray(context.includeLocales); | ||
}, | ||
buildContext() { | ||
let momentPath = this.findModulePath('moment'); | ||
let config = this.project.config(process.env.EMBER_ENV) || {}; | ||
let context = Object.assign( | ||
{ | ||
momentPath: momentPath, | ||
includeTimezone: null, | ||
includeLocales: [] | ||
}, | ||
config.moment | ||
); | ||
if (this.hasLocales(context)) { | ||
context.includeLocales = context.includeLocales | ||
.filter(locale => typeof locale === 'string') | ||
.map(locale => locale.replace('.js', '').trim().toLowerCase()) | ||
.map(locale => | ||
locale | ||
.replace('.js', '') | ||
.trim() | ||
.toLowerCase() | ||
) | ||
.filter(locale => { | ||
/* "en" is included by default. quietly ignore if user provides */ | ||
if (locale === 'en') { | ||
// `en` is included by default. quietly ignore if user specifies it in the list | ||
return false; | ||
} | ||
if (!existsSync(momentPath + '/locale/' + locale + '.js')) { | ||
this.ui.writeLine( | ||
chalk.red( | ||
'ember-cli-moment-shim: Specified locale `' + | ||
locale + | ||
'` but could not find in moment/locale.\nVisit https://github.com/moment/moment/tree/master/locale to view the full list of supported locales.' | ||
) | ||
if (!existsSync(`${momentPath}/locale/${locale}.js`)) { | ||
this.writeLine( | ||
`Specified locale '${locale} but could not find in moment/locale.\n` + | ||
`Visit https://github.com/moment/moment/tree/master/locale to view the full list of supported locales.`, | ||
'red' | ||
); | ||
@@ -118,9 +152,11 @@ return false; | ||
return config; | ||
return context; | ||
}, | ||
treeForPublic() { | ||
let hasFastBoot = this.project.addons.some(addon => addon.name === 'ember-cli-fastboot'); | ||
let hasFastBoot = this.project.addons.some( | ||
addon => addon.name === 'ember-cli-fastboot' | ||
); | ||
let publicTree = this._super.treeForPublic.apply(this, arguments); | ||
let options = this._options; | ||
let context = this.context; | ||
let trees = []; | ||
@@ -132,7 +168,7 @@ | ||
if (options.localeOutputPath) { | ||
if (context.localeOutputPath) { | ||
trees.push( | ||
funnel(this.momentNode, { | ||
srcDir: 'locale', | ||
destDir: options.localeOutputPath | ||
destDir: context.localeOutputPath | ||
}) | ||
@@ -145,5 +181,33 @@ ); | ||
pathsForOptions(context) { | ||
switch (context.includeTimezone) { | ||
case 'all': | ||
return [ | ||
'builds/moment-timezone-with-data.js', | ||
'builds/moment-timezone-with-data.min.js' | ||
]; | ||
case '2010-2020': | ||
this.writeLine( | ||
`"2010-2020" is deprecated, use "subset" within config/environment\n` + | ||
`Explanation can be found @ https://github.com/jasonmit/ember-cli-moment-shim/issues/121` | ||
); | ||
case 'subset': | ||
case '2012-2022': | ||
case '2010-2020': | ||
return [ | ||
'builds/moment-timezone-with-data-*.js', | ||
'builds/moment-timezone-with-data-*.min.js' | ||
]; | ||
case 'none': | ||
return ['moment-timezone.js', 'builds/moment-timezone.min.js']; | ||
default: | ||
throw new Error( | ||
'ember-cli-moment-shim: Please specify the moment-timezone dataset to include as either "all", "subset", or "none".' | ||
); | ||
} | ||
}, | ||
treeForVendor(vendorTree) { | ||
let trees = []; | ||
let options = this._options; | ||
let context = this.context; | ||
@@ -158,11 +222,15 @@ if (vendorTree) { | ||
include: [new RegExp(/\.js$/)], | ||
exclude: ['tests', 'ender', 'package'].map(key => new RegExp(key + '\.js$')) | ||
exclude: ['tests', 'ender', 'package'].map( | ||
key => new RegExp(key + '.js$') | ||
) | ||
}) | ||
); | ||
if (Array.isArray(options.includeLocales) && options.includeLocales.length) { | ||
if (this.hasLocales(context) && context.includeLocales.length) { | ||
let localeTree = funnel(this.momentNode, { | ||
srcDir: 'locale', | ||
destDir: 'moment/locales', | ||
include: options.includeLocales.map(locale => new RegExp(locale + '\.js$')) | ||
include: context.includeLocales.map( | ||
locale => new RegExp(locale + '.js$') | ||
) | ||
}); | ||
@@ -173,35 +241,8 @@ | ||
if (options.includeTimezone) { | ||
let timezonePath; | ||
let timezoneMinPath; | ||
if (context.includeTimezone) { | ||
let [timezonePath, timezoneMinPath] = this.pathsForOptions(context); | ||
let timezoneNode = new UnwatchedDir( | ||
this.findModulePath('moment-timezone') | ||
); | ||
switch (options.includeTimezone) { | ||
case 'all': | ||
timezonePath = 'builds/moment-timezone-with-data.js'; | ||
timezoneMinPath = 'builds/moment-timezone-with-data.min.js'; | ||
break; | ||
case '2010-2020': | ||
this.ui.writeLine( | ||
chalk.yellow( | ||
'[ember-cli-moment-shim] "2010-2020" is deprecated, use "subset" within config/environment\nDiscussion: https://github.com/jasonmit/ember-cli-moment-shim/issues/121' | ||
) | ||
); | ||
case 'subset': | ||
case '2012-2022': | ||
case '2010-2020': | ||
timezonePath = 'builds/moment-timezone-with-data-*.js'; | ||
timezoneMinPath = 'builds/moment-timezone-with-data-*.min.js'; | ||
break; | ||
case 'none': | ||
timezonePath = 'moment-timezone.js'; | ||
timezoneMinPath = 'builds/moment-timezone.min.js'; | ||
break; | ||
default: | ||
throw new Error( | ||
'ember-cli-moment-shim: Please specify the moment-timezone dataset to include as either "all", "subset", or "none".' | ||
); | ||
} | ||
const timezoneNode = new UnwatchedDir(path.dirname(require.resolve('moment-timezone'))); | ||
trees.push( | ||
@@ -222,4 +263,7 @@ rename( | ||
return map(mergeTrees(trees), (content) => `if (typeof FastBoot === 'undefined') { ${content} }`); | ||
return map( | ||
mergeTrees(trees), | ||
content => `if (typeof FastBoot === 'undefined') { ${content} }` | ||
); | ||
} | ||
}; |
{ | ||
"name": "ember-cli-moment-shim", | ||
"version": "3.5.0", | ||
"version": "3.5.1", | ||
"description": "Brings moment and moment-timezone into your Ember applications", | ||
@@ -38,4 +38,3 @@ "keywords": [ | ||
"exists-sync": "^0.0.4", | ||
"lodash.defaults": "^4.2.0", | ||
"moment": "^2.18.1", | ||
"moment": "^2.19.3", | ||
"moment-timezone": "^0.5.13" | ||
@@ -42,0 +41,0 @@ }, |
@@ -20,9 +20,5 @@ # ember-cli-moment-shim | ||
* ES6 accessible module for moment | ||
* Trim your build sizes by bundling locales & timezones data through simple configuration | ||
* Trim your build sizes by bundling locale & timezone data through simple configuration | ||
* FastBoot support | ||
## Upgrading | ||
Be sure to rerun the default blueprint with `ember g ember-cli-moment-shim` if upgrading by bumping the version number in package.json. | ||
## Enabling moment-timezone | ||
@@ -55,3 +51,3 @@ | ||
// To cherry-pick specific locale support into your application. | ||
// Full list of locales: https://github.com/moment/moment/tree/2.10.3/locale | ||
// Full list of locales: https://github.com/moment/moment/tree/master/locale | ||
includeLocales: ['es', 'fr-ca'] | ||
@@ -62,3 +58,3 @@ } | ||
*NOTE: English is bundled automatically, not need to add `en` in `includeLocales`* | ||
*NOTE: English is bundled automatically – no need to add `en` in `includeLocales`* | ||
@@ -91,3 +87,3 @@ ### Include all locales | ||
### Write all the locales to a folder relative to `dist` | ||
### Write all locales to a folder that is relative to `dist` | ||
@@ -106,3 +102,3 @@ ```js | ||
Feature set of i18n support within moment can be found here: http://momentjs.com/docs/#/i18n/ | ||
The feature set for i18n support within moment can be found here: http://momentjs.com/docs/#/i18n/ | ||
@@ -109,0 +105,0 @@ ## License |
Sorry, the diff of this file is not supported yet
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
213207
10
263
108
2
- Removedlodash.defaults@^4.2.0
- Removedlodash.defaults@4.2.0(transitive)
Updatedmoment@^2.19.3