Socket
Socket
Sign inDemoInstall

ember-cli-moment-shim

Package Overview
Dependencies
231
Maintainers
2
Versions
40
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.5.1 to 3.5.2

192

index.js

@@ -8,2 +8,3 @@ /* globals require, module, process */

const mergeTrees = require('broccoli-merge-trees');
const defaults = require('lodash.defaults');
const funnel = require('broccoli-funnel');

@@ -23,36 +24,15 @@ const existsSync = require('exists-sync');

this._super.included.apply(this, arguments);
this.context = this.buildContext();
this.momentNode = new UnwatchedDir(this.context.momentPath);
this.importDependencies(this.context);
this._options = this.getOptions();
this.momentNode = new UnwatchedDir(this._options.momentPath);
this.importDependencies();
},
findModulePath(moduleName) {
try {
let resolve = require('resolve');
updateFastBootManifest(manifest) {
let target = 'fastboot-moment.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;
}
if (this._options.includeTimezone) {
target = 'fastboot-moment-timezone.js'
}
},
updateFastBootManifest(manifest) {
if (this.context.includeTimezone) {
manifest.vendorFiles.push('moment/fastboot-moment-timezone.js');
} else {
manifest.vendorFiles.push('moment/fastboot-moment.js');
}
manifest.vendorFiles.push('moment/' + target);

@@ -62,4 +42,6 @@ return manifest;

importDependencies(context) {
if (context.includeTimezone) {
importDependencies() {
let options = this._options;
if (options.includeTimezone) {
this.import(

@@ -74,3 +56,3 @@ {

if (typeof context.includeLocales === 'boolean' && context.includeLocales) {
if (typeof options.includeLocales === 'boolean' && options.includeLocales) {
this.import(

@@ -84,7 +66,5 @@ {

} else {
if (this.hasLocales(context)) {
context.includeLocales.forEach(locale => {
this.import('vendor/moment/locales/' + locale + '.js', {
prepend: true
});
if (Array.isArray(options.includeLocales)) {
options.includeLocales.forEach(locale => {
this.import('vendor/moment/locales/' + locale + '.js', { prepend: true });
});

@@ -103,42 +83,28 @@ }

writeLine(msg = '', color = 'yellow') {
this.ui.writeLine(chalk[color](`ember-cli-moment-shim: ${msg}`));
},
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: []
});
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
if (Array.isArray(config.includeLocales)) {
config.includeLocales = config.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.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'
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.'
)
);

@@ -152,11 +118,9 @@ return false;

return context;
return config;
},
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 context = this.context;
let options = this._options;
let trees = [];

@@ -168,7 +132,7 @@

if (context.localeOutputPath) {
if (options.localeOutputPath) {
trees.push(
funnel(this.momentNode, {
srcDir: 'locale',
destDir: context.localeOutputPath
destDir: options.localeOutputPath
})

@@ -180,29 +144,24 @@ );

},
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".'
);
}
pathsForOptions({ includeTimezone }) {
switch (includeTimezone) {
case 'all':
return ['builds/moment-timezone-with-data.js', 'builds/moment-timezone-with-data.min.js'];
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':
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".'
);
}
},

@@ -212,3 +171,3 @@

let trees = [];
let context = this.context;
let options = this._options;

@@ -223,15 +182,11 @@ 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 (this.hasLocales(context) && context.includeLocales.length) {
if (Array.isArray(options.includeLocales) && options.includeLocales.length) {
let localeTree = funnel(this.momentNode, {
srcDir: 'locale',
destDir: 'moment/locales',
include: context.includeLocales.map(
locale => new RegExp(locale + '.js$')
)
include: options.includeLocales.map(locale => new RegExp(locale + '\.js$'))
});

@@ -242,7 +197,5 @@

if (context.includeTimezone) {
let [timezonePath, timezoneMinPath] = this.pathsForOptions(context);
let timezoneNode = new UnwatchedDir(
this.findModulePath('moment-timezone')
);
if (options.includeTimezone) {
let [ timezonePath, timezoneMinPath ] = this.pathsForOptions(options);
let timezoneNode = new UnwatchedDir(path.dirname(require.resolve('moment-timezone')));

@@ -264,7 +217,4 @@ trees.push(

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.1",
"version": "3.5.2",
"description": "Brings moment and moment-timezone into your Ember applications",

@@ -38,2 +38,3 @@ "keywords": [

"exists-sync": "^0.0.4",
"lodash.defaults": "^4.2.0",
"moment": "^2.19.3",

@@ -40,0 +41,0 @@ "moment-timezone": "^0.5.13"

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc