@ember-decorators/utils
Advanced tools
Comparing version 5.1.4 to 5.2.0
@@ -1,28 +0,26 @@ | ||
import { NEEDS_STAGE_1_DECORATORS } from 'ember-decorators-flags'; | ||
function isStage1ClassDescriptor(possibleDesc) { | ||
let [target] = possibleDesc; | ||
let isStage1FieldDescriptor; | ||
return ( | ||
possibleDesc.length === 1 && | ||
typeof target === 'function' && | ||
'prototype' in target && | ||
!target.__isComputedDecorator | ||
); | ||
} | ||
if (NEEDS_STAGE_1_DECORATORS) { | ||
isStage1FieldDescriptor = function isStage1FieldDescriptor(possibleDesc) { | ||
if (possibleDesc.length === 3) { | ||
let [target, key, desc] = possibleDesc; | ||
function isStage1FieldDescriptor(possibleDesc) { | ||
let [target, key, desc] = possibleDesc; | ||
return ( | ||
typeof target === 'object' && | ||
target !== null && | ||
typeof key === 'string' && | ||
((typeof desc === 'object' && | ||
desc !== null && | ||
'enumerable' in desc && | ||
'configurable' in desc) || | ||
desc === undefined) // TS compatibility | ||
); | ||
} else if (possibleDesc.length === 1) { | ||
let [target] = possibleDesc; | ||
return typeof target === 'function' && 'prototype' in target && !target.__isComputedDecorator; | ||
} | ||
return false; | ||
}; | ||
return ( | ||
possibleDesc.length === 3 && | ||
typeof target === 'object' && | ||
target !== null && | ||
typeof key === 'string' && | ||
((typeof desc === 'object' && | ||
desc !== null && | ||
'enumerable' in desc && | ||
'configurable' in desc) || | ||
desc === undefined) // TS compatibility | ||
); | ||
} | ||
@@ -35,9 +33,7 @@ | ||
export function isFieldDescriptor(possibleDesc) { | ||
let isDescriptor = isStage2FieldDescriptor(possibleDesc); | ||
return isStage2FieldDescriptor(possibleDesc) || isStage1FieldDescriptor(possibleDesc); | ||
} | ||
if (NEEDS_STAGE_1_DECORATORS) { | ||
isDescriptor = isDescriptor || isStage1FieldDescriptor(possibleDesc); | ||
} | ||
return isDescriptor; | ||
export function isDescriptor(possibleDesc) { | ||
return isFieldDescriptor(possibleDesc) || isStage1ClassDescriptor(possibleDesc); | ||
} | ||
@@ -44,0 +40,0 @@ |
@@ -23,3 +23,3 @@ import { DEBUG } from '@glimmer/env'; | ||
export function isComputedDescriptor(possibleDesc) { | ||
return possibleDesc !== null && typeof possibleDesc === 'object' && possibleDesc.isDescriptor; | ||
return possibleDesc !== null && (typeof possibleDesc === 'object' || typeof possibleDesc === 'function') && possibleDesc.isDescriptor; | ||
} | ||
@@ -26,0 +26,0 @@ |
import { defineProperty } from '@ember/object'; | ||
import { HAS_NATIVE_COMPUTED_GETTERS, gte } from 'ember-compatibility-helpers'; | ||
import { NEEDS_STAGE_1_DECORATORS } from 'ember-decorators-flags'; | ||
@@ -10,3 +9,3 @@ import { decorator } from './decorator'; | ||
import { DEBUG } from '@glimmer/env'; | ||
import { assert } from '@ember/debug'; | ||
import { assert, deprecate } from '@ember/debug'; | ||
import ComputedProperty from '@ember/object/computed'; | ||
@@ -48,7 +47,25 @@ | ||
computedDecorator = function(fn, params) { | ||
computedDecorator = function(fn, params, name, importDesc) { | ||
let computed = params === undefined ? fn() : fn(...params); | ||
let decorator = (...args) => { | ||
deprecate( | ||
`You are using @${name} decorator from ember-decorators. This decorator is deprecated, you can now use Ember's built in decorators directly. Install the ember-decorators-polyfill (https://github.com/pzuraq/ember-decorators-polyfill), and replace your imports with imports from Ember:\n\n \`${importDesc};\`\n\n`, | ||
false, | ||
{ | ||
id: 'computed-deprecations', | ||
until: '6.0.0', | ||
} | ||
); | ||
if (isStage2FieldDescriptor(args)) { | ||
deprecate( | ||
'You are using the stage 2 decorator trasforms (@ember-decorators/babel-transforms v3-v5). Ember has officially adopted the stage 1 transforms instead. The stage 2 transforms will not be supported in ember-decorators v6. You can update `ember-cli-babel` to the latest version (at least 7.7.3) and remove @ember-decorators/babel-transforms from your app/addon.', | ||
false, | ||
{ | ||
id: 'action-deprecation', | ||
until: '6.0.0', | ||
} | ||
); | ||
let desc = args[0]; | ||
@@ -81,3 +98,4 @@ | ||
Ember._setComputedDecorator(decorator); | ||
let setClassicDecorator = Ember._setClassicDecorator || Ember._setComputedDecorator; | ||
setClassicDecorator(decorator); | ||
@@ -128,3 +146,3 @@ if (DEBUG) { | ||
if (gte('3.6.0')) { | ||
if (this._computedDesc.__IS_POLYFILLED_COMPUTED || gte('3.6.0')) { | ||
this._computedDesc.setup(obj, key, meta); | ||
@@ -188,4 +206,14 @@ } else if (gte('3.1.0')) { | ||
computedDecorator = function(fn, params) { | ||
computedDecorator = function(fn, params, name, importDesc) { | ||
let deprecationMessage = | ||
name === 'wrapComputed' | ||
? 'The wrapComputed() wrapper is no longer necessary with, with the ember-decorators-polyfill, all computed properties are now decorators: https://github.com/pzuraq/ember-decorators-polyfill' | ||
: `You are using @${name} decorator from ember-decorators. This decorator is deprecated, you can now use Ember's built in decorators directly. Install the ember-decorators-polyfill (https://github.com/pzuraq/ember-decorators-polyfill), and replace your imports with imports from Ember:\n\n \`${importDesc};\`\n\n`; | ||
let dec = decorator(desc => { | ||
deprecate(deprecationMessage, false, { | ||
id: 'computed-deprecations', | ||
until: '6.0.0', | ||
}); | ||
// All computeds are methods | ||
@@ -220,7 +248,5 @@ desc.kind = 'method'; | ||
if (NEEDS_STAGE_1_DECORATORS) { | ||
// There's currently no way to disable redefining the property when decorators | ||
// are run, so return the property descriptor we just assigned | ||
desc.descriptor = Object.getOwnPropertyDescriptor(prototype, key); | ||
} | ||
// There's currently no way to disable redefining the property when decorators | ||
// are run, so return the property descriptor we just assigned | ||
desc.descriptor = Object.getOwnPropertyDescriptor(prototype, key); | ||
@@ -247,11 +273,8 @@ return target; | ||
export function computedDecoratorWithParams(fn) { | ||
export function computedDecoratorWithParams(fn, name, desc) { | ||
return function(...params) { | ||
if (isFieldDescriptor(params)) { | ||
// Funkiness of application call here is due to `...params` transpiling to | ||
// use `apply`, which is no longer on the prototype of the computedDecorator | ||
// since it has had it's prototype changed :upside_down_face: | ||
return Function.apply.call(computedDecorator(fn), undefined, params); | ||
return Function.apply.call(computedDecorator(fn, undefined, name, desc), undefined, params); | ||
} else { | ||
return computedDecorator(fn, params); | ||
return computedDecorator(fn, params, name, desc); | ||
} | ||
@@ -261,3 +284,3 @@ }; | ||
export function computedDecoratorWithRequiredParams(fn, name) { | ||
export function computedDecoratorWithRequiredParams(fn, name, desc) { | ||
return function(...params) { | ||
@@ -269,4 +292,4 @@ assert( | ||
return computedDecorator(fn, params); | ||
return computedDecorator(fn, params, name, desc); | ||
}; | ||
} |
@@ -1,8 +0,5 @@ | ||
import { assert } from '@ember/debug'; | ||
import { assert, deprecate } from '@ember/debug'; | ||
import { NEEDS_STAGE_1_DECORATORS } from 'ember-decorators-flags'; | ||
import { deprecate } from '@ember/application/deprecations'; | ||
import { | ||
isFieldDescriptor, | ||
isDescriptor, | ||
isStage2FieldDescriptor, | ||
@@ -12,56 +9,43 @@ convertStage1ToStage2, | ||
function deprecateDirectDescriptorMutation(fn, desc) { | ||
let returnValue = fn(desc); | ||
if (!returnValue) { | ||
deprecate( | ||
`@ember-decorators/utils: Directly mutating the descriptor by reference is deprecated. Return it instead.`, | ||
false, | ||
{ | ||
id: 'ember-decorators.utils.decorator.descriptor-mutation-by-reference', | ||
until: '4.0.0', | ||
} | ||
); | ||
return desc; | ||
} | ||
return returnValue; | ||
} | ||
export function decorator(fn) { | ||
if (NEEDS_STAGE_1_DECORATORS) { | ||
return function(...params) { | ||
if (isStage2FieldDescriptor(params)) { | ||
let desc = params[0]; | ||
return function(...params) { | ||
if (isStage2FieldDescriptor(params)) { | ||
deprecate( | ||
'You are using the stage 2 decorator trasforms (@ember-decorators/babel-transforms v3-v5). Ember has officially adopted the stage 1 transforms instead. The stage 2 transforms will not be supported in ember-decorators v6. You can update `ember-cli-babel` to the latest version (at least 7.7.3) and remove @ember-decorators/babel-transforms from your app/addon.', | ||
false, | ||
{ | ||
id: 'action-deprecation', | ||
until: '6.0.0', | ||
} | ||
); | ||
return deprecateDirectDescriptorMutation(fn, desc); | ||
} else { | ||
let desc = convertStage1ToStage2(params); | ||
let desc = params[0]; | ||
desc = deprecateDirectDescriptorMutation(fn, desc); | ||
return fn(desc); | ||
} else { | ||
let desc = convertStage1ToStage2(params); | ||
if (typeof desc.finisher === 'function') { | ||
// Finishers are supposed to run at the end of class finalization, | ||
// but we don't get that with stage 1 transforms. We have to be careful | ||
// to make sure that we aren't doing any operations which would change | ||
// due to timing. | ||
let [target] = params; | ||
desc = fn(desc) || desc; | ||
desc.finisher(target.prototype ? target : target.constructor); | ||
} | ||
if (typeof desc.finisher === 'function') { | ||
// Finishers are supposed to run at the end of class finalization, | ||
// but we don't get that with stage 1 transforms. We have to be careful | ||
// to make sure that we aren't doing any operations which would change | ||
// due to timing. | ||
let [target] = params; | ||
if (typeof desc.initializer === 'function') { | ||
// Babel 6 / the legacy decorator transform needs the initializer back | ||
// on the property descriptor/ In case the user has set a new | ||
// initializer on the member descriptor, we transfer it back to | ||
// original descriptor. | ||
desc.descriptor.initializer = desc.initializer; | ||
} | ||
desc.finisher(target.prototype ? target : target.constructor); | ||
} | ||
return desc.descriptor; | ||
if (typeof desc.initializer === 'function') { | ||
// Babel 6 / the legacy decorator transform needs the initializer back | ||
// on the property descriptor/ In case the user has set a new | ||
// initializer on the member descriptor, we transfer it back to | ||
// original descriptor. | ||
desc.descriptor.initializer = desc.initializer; | ||
} | ||
}; | ||
} else { | ||
return fn; | ||
} | ||
return desc.descriptor; | ||
} | ||
}; | ||
} | ||
@@ -89,3 +73,3 @@ | ||
// determine if user called as @computed('blah', 'blah') or @computed | ||
if (isFieldDescriptor(params)) { | ||
if (isDescriptor(params)) { | ||
return decorator(fn)(...params); | ||
@@ -119,3 +103,3 @@ } else { | ||
`The @${name || fn.name} decorator requires parameters`, | ||
!isFieldDescriptor(params) && params.length > 0 | ||
!isDescriptor(params) && params.length > 0 | ||
); | ||
@@ -122,0 +106,0 @@ |
156
index.js
@@ -1,159 +0,3 @@ | ||
const semver = require('semver'); | ||
const VersionChecker = require('ember-cli-version-checker'); | ||
const PLUGIN_NAME = 'ember-decorators-debug-macros'; | ||
// used as a way to memoize needsStage1Decorators so that we can avoid many many | ||
// top down searches of the addon heirarchy | ||
const NEEDS_STAGE_1_DECORATORS = new WeakMap(); | ||
function cleanVersion(version) { | ||
if (version === undefined) return false; | ||
let matchedVersion = version.match(/\d\.\d\.\d/); | ||
return matchedVersion && matchedVersion[0]; | ||
} | ||
function checkNeedsStage1Decorators(project) { | ||
if (NEEDS_STAGE_1_DECORATORS.has(project)) { | ||
return NEEDS_STAGE_1_DECORATORS.get(project); | ||
} | ||
let needsStage1Decorators = checkAddonsForStage1(project, project); | ||
NEEDS_STAGE_1_DECORATORS.set(project, !!needsStage1Decorators); | ||
return needsStage1Decorators; | ||
} | ||
function checkAddonsForStage1(project, addonOrProject) { | ||
if (!addonOrProject.pkg) { | ||
// for some reason we couldn't read package.json, return true to be safe | ||
project.ui.writeWarnLine(`unable to read package.json for ${addonOrProject.name}, including stage 1 decorators by default`); | ||
return true; | ||
} | ||
let { dependencies = {}, devDependencies = {} } = addonOrProject.pkg; | ||
let checker = new VersionChecker(addonOrProject); | ||
// check if decorators are in deps at all. We must check directly because it's | ||
// possible to "bubble" up to the main app's decorators, and we may give a | ||
// false positive. | ||
let hasDecorators = [ | ||
'ember-decorators', | ||
'@ember-decorators/component', | ||
'@ember-decorators/controller', | ||
'@ember-decorators/data', | ||
'@ember-decorators/object', | ||
'@ember-decorators/service', | ||
'@ember-decorators/utils', | ||
].some(d => d in dependencies); | ||
// check the resolved version of decorators. This could end up being the root | ||
// application's version of decorators, so we need to use ec-version-checker. | ||
let hasOlderDecorators = checker.for('@ember-decorators/utils', 'npm').lt('3.1.0'); | ||
// If embroiderer comes through this will need to update. | ||
let hasOlderTransforms = checker.for('@ember-decorators/babel-transforms', 'npm').lt('3.1.0'); | ||
// If the dev dependency exists and is readable, we use that. Otherwise, we | ||
// default to the installed version if it exists. This should cover in-repo | ||
// addons/engines, while also covering most addons that used TS in development | ||
// and shipped built packages. | ||
let devTSVersion = cleanVersion(devDependencies['ember-cli-typescript']); | ||
let hasOlderTypescript = | ||
(devTSVersion && semver.lt(devTSVersion, '2.0.0-beta.1')) || | ||
checker.for('ember-cli-typescript', 'npm').lt('2.0.0-beta.1'); | ||
let needsStage1 = false; | ||
let addonOrProjectMessage = | ||
addonOrProject.isEmberCLIProject && addonOrProject.isEmberCLIProject() | ||
? 'Your app' | ||
: `The '${addonOrProject.name}' addon`; | ||
if (hasDecorators && hasOlderTypescript) { | ||
project.ui.writeWarnLine( | ||
`${addonOrProjectMessage} is using an older version of ember-cli-typescript that uses stage 1 decorators. Please update to ember-cli-typescript@v2 to remove your dependency on legacy decorators.` | ||
); | ||
needsStage1 = true; | ||
} | ||
if (hasDecorators && hasOlderTransforms) { | ||
project.ui.writeWarnLine( | ||
`${addonOrProjectMessage} is using an older version of @ember-decorators/babel-transforms that uses stage 1 decorators. Please update to @ember-decorators/babel-transforms@v3.1 to remove your dependency on legacy decorators.` | ||
); | ||
needsStage1 = true; | ||
} | ||
if (hasDecorators && hasOlderDecorators) { | ||
project.ui.writeWarnLine( | ||
`${addonOrProjectMessage} is using an older version of ember-decorators that uses stage 1 decorators. Please update to ember-decorators@v3.1 to remove your dependency on legacy decorators.` | ||
); | ||
needsStage1 = true; | ||
} | ||
// return late so we print all possible warnings | ||
if (needsStage1) { | ||
return true; | ||
} | ||
if (addonOrProject.addons) { | ||
return addonOrProject.addons.some(addon => checkAddonsForStage1(project, addon)); | ||
} | ||
return false; | ||
} | ||
function setupBabelPlugins(project, addon) { | ||
addon.options = addon.options || {}; | ||
addon.options.babel = addon.options.babel || {}; | ||
let plugins = (addon.options.babel.plugins = addon.options.babel.plugins || []); | ||
// If the plugin is already configure, skip. | ||
if (plugins.some(p => Array.isArray(p) && p[2] === PLUGIN_NAME)) return; | ||
let needsStage1Decorators = | ||
process.env.EMBER_DECORATORS_NEEDS_STAGE_1_DECORATORS === 'true' || | ||
checkNeedsStage1Decorators(project); | ||
let pluginOptions = { | ||
debugTools: { | ||
isDebug: false, | ||
source: 'ember-decorators-flags', | ||
}, | ||
flags: [ | ||
{ | ||
name: 'ember-decorators-flags', | ||
source: 'ember-decorators-flags', | ||
flags: { | ||
NEEDS_STAGE_1_DECORATORS: needsStage1Decorators, | ||
}, | ||
} | ||
] | ||
}; | ||
plugins.push([require.resolve('babel-plugin-debug-macros'), pluginOptions, PLUGIN_NAME]); | ||
} | ||
module.exports = { | ||
name: '@ember-decorators/utils', | ||
included(includer) { | ||
this._super.included.apply(this, arguments); | ||
let host = this._findHost(); | ||
let hostOptions = (host.options && host.options['@ember-decorators']) || {}; | ||
setupBabelPlugins(this.project, this, hostOptions); | ||
setupBabelPlugins(this.project, includer, hostOptions); | ||
}, | ||
}; |
{ | ||
"name": "@ember-decorators/utils", | ||
"version": "5.1.4", | ||
"version": "5.2.0", | ||
"description": "Utilities used by the Ember Decorators project", | ||
@@ -28,12 +28,12 @@ "keywords": [ | ||
"ember-compatibility-helpers": "^1.1.2", | ||
"semver": "^5.6.0" | ||
"semver": "^6.0.0" | ||
}, | ||
"devDependencies": { | ||
"@ember-decorators/babel-transforms": "^5.1.4", | ||
"@types/ember": "3.0.26", | ||
"@types/ember-data": "3.1.3", | ||
"@ember-decorators/babel-transforms": "^5.2.0", | ||
"@types/ember": "3.0.27", | ||
"@types/ember-data": "3.1.4", | ||
"@types/ember-testing-helpers": "0.0.3", | ||
"@types/rsvp": "4.0.2", | ||
"broccoli-asset-rev": "^3.0.0", | ||
"ember-ajax": "^4.0.0", | ||
"ember-ajax": "^5.0.0", | ||
"ember-cli": "~3.0.0", | ||
@@ -62,3 +62,3 @@ "ember-cli-dependency-checker": "^3.0.0", | ||
}, | ||
"gitHead": "610569c29a7ff7e113fe9c6cf1a2d0994b69d64d" | ||
"gitHead": "f3e3d636a38d99992af326a1012d69bf10a2cb4c" | ||
} |
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
0
21589
505
Updatedsemver@^6.0.0