-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BREAKING] Convert to a module, drops support for Ember < 3.28
- Loading branch information
Showing
9 changed files
with
526 additions
and
417 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,3 @@ | ||
## v2.0.0 (2021-07-04) | ||
|
||
|
||
## v2.0.0-beta.5 (2021-07-04) | ||
|
||
#### :bug: Bug Fix | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
import { registerDeprecationHandler } from '@ember/debug'; | ||
|
||
const LOG_LIMIT = 100; | ||
|
||
export default function setupDeprecationWorkflow(config) { | ||
self.deprecationWorkflow = self.deprecationWorkflow || {}; | ||
self.deprecationWorkflow.deprecationLog = { | ||
messages: {}, | ||
}; | ||
|
||
registerDeprecationHandler((message, options, next) => | ||
handleDeprecationWorkflow(config, message, options, next) | ||
); | ||
|
||
registerDeprecationHandler(deprecationCollector); | ||
|
||
self.deprecationWorkflow.flushDeprecations = flushDeprecations; | ||
} | ||
|
||
let preamble = `import setupDeprecationWorkflow from 'ember-cli-deprecation-workflow'; | ||
setupDeprecationWorkflow({ | ||
workflow: [ | ||
`; | ||
|
||
let postamble = ` ] | ||
});`; | ||
|
||
export function detectWorkflow(config, message, options) { | ||
if (!config || !config.workflow) { | ||
return; | ||
} | ||
|
||
let i, workflow, matcher, idMatcher; | ||
for (i = 0; i < config.workflow.length; i++) { | ||
workflow = config.workflow[i]; | ||
matcher = workflow.matchMessage; | ||
idMatcher = workflow.matchId; | ||
|
||
if (typeof idMatcher === 'string' && options && idMatcher === options.id) { | ||
return workflow; | ||
} else if (typeof matcher === 'string' && matcher === message) { | ||
return workflow; | ||
} else if (matcher instanceof RegExp && matcher.exec(message)) { | ||
return workflow; | ||
} | ||
} | ||
} | ||
|
||
export function flushDeprecations() { | ||
let messages = self.deprecationWorkflow.deprecationLog.messages; | ||
let logs = []; | ||
|
||
for (let message in messages) { | ||
logs.push(messages[message]); | ||
} | ||
|
||
let deprecations = logs.join(',\n') + '\n'; | ||
|
||
return preamble + deprecations + postamble; | ||
} | ||
|
||
export function handleDeprecationWorkflow(config, message, options, next) { | ||
let matchingWorkflow = detectWorkflow(config, message, options); | ||
if (!matchingWorkflow) { | ||
if (config && config.throwOnUnhandled) { | ||
throw new Error(message); | ||
} else { | ||
next(message, options); | ||
} | ||
} else { | ||
switch (matchingWorkflow.handler) { | ||
case 'silence': | ||
// no-op | ||
break; | ||
case 'log': { | ||
let key = (options && options.id) || message; | ||
|
||
if (!self.deprecationWorkflow.logCounts) { | ||
self.deprecationWorkflow.logCounts = {}; | ||
} | ||
|
||
let count = self.deprecationWorkflow.logCounts[key] || 0; | ||
self.deprecationWorkflow.logCounts[key] = ++count; | ||
|
||
if (count <= LOG_LIMIT) { | ||
console.warn('DEPRECATION: ' + message); | ||
if (count === LOG_LIMIT) { | ||
console.warn( | ||
'To avoid console overflow, this deprecation will not be logged any more in this run.' | ||
); | ||
} | ||
} | ||
|
||
break; | ||
} | ||
case 'throw': | ||
throw new Error(message); | ||
default: | ||
next(message, options); | ||
break; | ||
} | ||
} | ||
} | ||
|
||
export function deprecationCollector(message, options, next) { | ||
let key = (options && options.id) || message; | ||
let matchKey = options && key === options.id ? 'matchId' : 'matchMessage'; | ||
|
||
self.deprecationWorkflow.deprecationLog.messages[key] = | ||
' { handler: "silence", ' + matchKey + ': ' + JSON.stringify(key) + ' }'; | ||
|
||
next(message, options); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.