Skip to content

Commit

Permalink
Test usage of directly imported helpers (.gts / ember-template-import…
Browse files Browse the repository at this point in the history
…s) (#555)
  • Loading branch information
machty authored Feb 5, 2024
1 parent c6f92d1 commit ad03181
Show file tree
Hide file tree
Showing 86 changed files with 1,100 additions and 3,055 deletions.
6 changes: 5 additions & 1 deletion packages/ember-concurrency/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ module.exports = {
extends: [
'eslint:recommended',
'plugin:ember/recommended',
'plugin:prettier/recommended',

// This invokes "eslint-config-prettier" to disable ESLint rules that conflict with Prettier.
// Not to be confused with "eslint-plugin-prettier" which runs Prettier as an ESLint rule
// (which we no longer use)
'prettier',
],
env: {
browser: true,
Expand Down
2 changes: 1 addition & 1 deletion packages/ember-concurrency/addon-main.cjs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
const { addonV1Shim } = require('@embroider/addon-shim');
const { addonV1Shim } = require("@embroider/addon-shim");
module.exports = addonV1Shim(__dirname);
24 changes: 12 additions & 12 deletions packages/ember-concurrency/async-arrow-task-transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ const TransformAsyncMethodsIntoGeneratorMethods = {
let rootModifierPath;

let maybeAsyncArrowPath = path.get(
`value.arguments.${value.arguments.length - 1}`
`value.arguments.${value.arguments.length - 1}`,
);
while (maybeAsyncArrowPath && maybeAsyncArrowPath.node) {
const maybeAsyncArrow = maybeAsyncArrowPath.node;
Expand All @@ -100,7 +100,7 @@ const TransformAsyncMethodsIntoGeneratorMethods = {
maybeAsyncArrowPath,
rootModifierPath,
state,
factoryFunctionName
factoryFunctionName,
);
break;
} else if (maybeAsyncArrow.type === 'CallExpression') {
Expand All @@ -120,7 +120,7 @@ function convertFunctionExpressionIntoGenerator(
taskFnPath,
rootModifierPath,
state,
factoryFunctionName
factoryFunctionName,
) {
if (taskFnPath && taskFnPath.node.async) {
if (isArrowFunctionExpression(taskFnPath)) {
Expand Down Expand Up @@ -160,7 +160,7 @@ function convertFunctionExpressionIntoGenerator(
taskFnPath.node.id,
taskFnPath.node.params,
asyncArrowFnBody,
true
true,
);

// Replace the async arrow task function with the generator function
Expand All @@ -178,17 +178,17 @@ function convertFunctionExpressionIntoGenerator(
// inside some modifier functions. Now we want to move that whole
// tree, including any modifier functions, into this generator
// property.
(rootModifierPath || taskFnPath).node
(rootModifierPath || taskFnPath).node,
),
])
]),
);

// Add an import to buildTask (if one hasn't already been added)
if (!state._buildTaskImport) {
state._buildTaskImport = addNamed(
state.root,
'buildTask',
'ember-concurrency/-private/async-arrow-runtime'
'ember-concurrency/-private/async-arrow-runtime',
);
}

Expand All @@ -213,7 +213,7 @@ function convertFunctionExpressionIntoGenerator(
break;
default:
throw new Error(
`The task() syntax you're using for the task named ${taskName} is incorrect.`
`The task() syntax you're using for the task named ${taskName} is incorrect.`,
);
}

Expand All @@ -229,7 +229,7 @@ function convertFunctionExpressionIntoGenerator(
optionsOrNull,
stringLiteral(taskName),
bufferPolicyName ? stringLiteral(bufferPolicyName) : nullLiteral(),
]
],
);

let newPath = taskPath.replaceWith(buildTaskCall)[0];
Expand Down Expand Up @@ -300,17 +300,17 @@ module.exports = declare((api) => {
ClassDeclaration(path, innerState) {
path.traverse(
TransformAsyncMethodsIntoGeneratorMethods,
innerState
innerState,
);
},
ClassExpression(path, innerState) {
path.traverse(
TransformAsyncMethodsIntoGeneratorMethods,
innerState
innerState,
);
},
},
state
state,
);
},
},
Expand Down
14 changes: 8 additions & 6 deletions packages/ember-concurrency/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
"lint:fix": "concurrently 'npm:lint:*:fix' --names 'fix:'",
"lint:hbs": "ember-template-lint .",
"lint:hbs:fix": "ember-template-lint . --fix",
"lint:js": "eslint . --cache",
"lint:js:fix": "eslint . --fix",
"lint:eslint": "eslint . --cache",
"lint:eslint:fix": "eslint . --fix",
"lint:prettier": "prettier . --cache --check",
"lint:prettier:fix": "prettier . --write",
"start": "rollup --config --watch",
"test": "echo 'Addon does not have tests, run tests in test-app'",
"prepare": "pnpm build"
Expand All @@ -32,14 +34,14 @@
"@tsconfig/ember": "^3.0.3",
"@typescript-eslint/eslint-plugin": "^6.14.0",
"@typescript-eslint/parser": "^6.14.0",
"ember-template-lint": "^5.6.0",
"babel-eslint": "^10.1.0",
"ember-template-lint": "^5.13.0",
"eslint": "^7.32.0",
"eslint-config-prettier": "^8.6.0",
"eslint-plugin-ember": "^11.4.7",
"eslint-plugin-ember": "^11.12.0",
"eslint-plugin-n": "^15.6.1",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-qunit": "^7.3.4",
"prettier": "^2.8.4",
"prettier": "^3.1.0",
"rollup": "^4.9.6",
"typescript": "^5.3.3"
},
Expand Down
6 changes: 3 additions & 3 deletions packages/ember-concurrency/rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default {
plugins: [
// These are the modules that users should be able to import from your
// addon. Anything not listed here may get optimized away.
addon.publicEntrypoints(['index.js', '**/*.js']),
addon.publicEntrypoints(["index.js", "**/*.js"]),

// These are the modules that should get reexported into the traditional
// "app" tree. Things in here should also be in publicEntrypoints above, but
Expand All @@ -33,8 +33,8 @@ export default {
// By default, this will load the actual babel config from the file
// babel.config.json.
babel({
extensions: ['.js', '.gjs', '.ts', '.gts'],
babelHelpers: 'bundled',
extensions: [".js", ".gjs", ".ts", ".gts"],
babelHelpers: "bundled",
}),

// Ensure that standalone .hbs files are properly integrated as Javascript.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function buildTask(contextFn, options, taskName, bufferPolicyName) {
const taskFactory = new TaskFactory(
taskName || '<unknown>',
result.generator,
optionsWithBufferPolicy
optionsWithBufferPolicy,
);
return taskFactory.createTask(result.context);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import BoundedPolicy from './bounded-policy';
import { makeCancelState, STARTED } from './execution-states';

const CANCELLED = makeCancelState(
`it belongs to a 'drop' Task that was already running`
`it belongs to a 'drop' Task that was already running`,
);

class DropReducer {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import BoundedPolicy from './bounded-policy';
import { STARTED, QUEUED, makeCancelState } from './execution-states';

const CANCELLED = makeCancelState(
`it belongs to a 'keepLatest' Task that was already running`
`it belongs to a 'keepLatest' Task that was already running`,
);

// Given:
Expand Down Expand Up @@ -44,7 +44,7 @@ class KeepLatestPolicy extends BoundedPolicy {
let totalRunning = numRunning + numQueued;
return new KeepLatestReducer(
this.maxConcurrency,
totalRunning - this.maxConcurrency - maxEnqueued
totalRunning - this.maxConcurrency - maxEnqueued,
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import BoundedPolicy from './bounded-policy';
import { STARTED, makeCancelState } from './execution-states';

const CANCELLED = makeCancelState(
`it belongs to a 'restartable' Task that was .perform()ed again`
`it belongs to a 'restartable' Task that was .perform()ed again`,
);

class RestartableReducer {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class Refresh {
numQueued: state.numQueued,
numPerformedInc: state.numPerformedInc,
},
state.attrs
state.attrs,
);

taskable.onState(props, taskable);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class Scheduler {
let refresh = new SchedulerRefresh(
this.schedulerPolicy,
stateTracker,
this.taskInstances
this.taskInstances,
);
this.taskInstances = refresh.process();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ function taskFromPropertyDescriptor(
key,
descriptor,
params = [],
factoryClass = TaskFactory
factoryClass = TaskFactory,
) {
let { initializer, get, value } = descriptor;
let taskFn;
Expand Down Expand Up @@ -44,7 +44,7 @@ function taskGroupPropertyDescriptor(
key,
_descriptor,
params = [],
factoryClass = TaskFactory
factoryClass = TaskFactory,
) {
let taskGroups = new WeakMap();
let options = params[0] || {};
Expand Down Expand Up @@ -101,19 +101,19 @@ function createDecorator(fn, baseOptions = {}, factoryClass = TaskFactory) {

export function createTaskDecorator(
baseOptions = {},
factoryClass = TaskFactory
factoryClass = TaskFactory,
) {
return createDecorator(taskFromPropertyDescriptor, baseOptions, factoryClass);
}

export function createTaskGroupDecorator(
baseOptions = {},
factoryClass = TaskFactory
factoryClass = TaskFactory,
) {
return createDecorator(
taskGroupPropertyDescriptor,
baseOptions,
factoryClass
factoryClass,
);
}

Expand All @@ -137,5 +137,5 @@ export const lastValue = decoratorWithParams(
return undefined;
},
};
}
},
);
16 changes: 8 additions & 8 deletions packages/ember-concurrency/src/-private/external/task-factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ import { DEFAULT_ENVIRONMENT } from './environment';
function assertModifiersNotMixedWithGroup(obj) {
if (obj._hasSetConcurrencyConstraint && obj._taskGroupPath) {
throw new Error(
`Cannot use both 'group' and other concurrency-constraining task modifiers (e.g. 'drop', 'enqueue', 'restartable')`
`Cannot use both 'group' and other concurrency-constraining task modifiers (e.g. 'drop', 'enqueue', 'restartable')`,
);
}
}

function assertUnsetBufferPolicy(obj) {
if (obj._hasSetBufferPolicy) {
throw new Error(
`Cannot set multiple buffer policies on a task or task group. ${obj._schedulerPolicyClass} has already been set for task or task group '${obj.name}'`
`Cannot set multiple buffer policies on a task or task group. ${obj._schedulerPolicyClass} has already been set for task or task group '${obj.name}'`,
);
}
}
Expand Down Expand Up @@ -58,7 +58,7 @@ const MODIFIER_REGISTRY = {
export function registerModifier(name, callback) {
if (MODIFIER_REGISTRY[name]) {
throw new Error(
`A modifier with the name '${name}' has already been defined.`
`A modifier with the name '${name}' has already been defined.`,
);
}

Expand Down Expand Up @@ -131,8 +131,8 @@ export class TaskFactory {
{
generatorFactory: (args) => this.taskDefinition.apply(context, args),
},
options
)
options,
),
);
}

Expand Down Expand Up @@ -200,18 +200,18 @@ export class TaskFactory {
group = context[this._taskGroupPath];
if (!(group instanceof TaskGroup)) {
throw new Error(
`Expected group '${this._taskGroupPath}' to be defined but was not found.`
`Expected group '${this._taskGroupPath}' to be defined but was not found.`,
);
}

scheduler = group.scheduler;
} else {
let schedulerPolicy = new this._schedulerPolicyClass(
this._maxConcurrency
this._maxConcurrency,
);
scheduler = this.getScheduler(
schedulerPolicy,
onStateCallback && typeof onStateCallback === 'function'
onStateCallback && typeof onStateCallback === 'function',
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export class TaskInstanceExecutor {
if (yieldResumeType === YIELDABLE_CANCEL) {
this.requestCancel(
new CancelRequest(CANCEL_KIND_YIELDABLE_CANCEL),
value
value,
);
this.proceedWithCancelAsync();
} else {
Expand Down Expand Up @@ -196,7 +196,7 @@ export class TaskInstanceExecutor {
},
(error) => {
this.proceedChecked(resumeIndex, YIELDABLE_THROW, error);
}
},
);
}

Expand Down Expand Up @@ -290,7 +290,7 @@ export class TaskInstanceExecutor {
if (!value || value.performType !== PERFORM_TYPE_LINKED) {
// eslint-disable-next-line no-console
console.warn(
'You performed a .linked() task without immediately yielding/returning it. This is currently unsupported (but might be supported in future version of ember-concurrency).'
'You performed a .linked() task without immediately yielding/returning it. This is currently unsupported (but might be supported in future version of ember-concurrency).',
);
}
this._expectsLinkedYield = false;
Expand Down Expand Up @@ -379,7 +379,7 @@ export class TaskInstanceExecutor {

finalizeWithCancel() {
let cancelReason = this.taskInstance.formatCancelReason(
this.cancelRequest.reason
this.cancelRequest.reason,
);
let error = new Error(cancelReason);

Expand Down Expand Up @@ -430,7 +430,7 @@ export class TaskInstanceExecutor {
try {
let maybeDisposer = yieldedValue[yieldableSymbol](
this.taskInstance,
this.index
this.index,
);
this.addDisposer(maybeDisposer);
} catch (e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export class Task extends Taskable {
let taskInstance = this._taskInstanceFactory(
fullArgs,
performType,
linkedObject
linkedObject,
);

if (performType === PERFORM_TYPE_LINKED) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class Taskable {

let cancelRequest = new CancelRequest(
cancelRequestKind || CANCEL_KIND_EXPLICIT,
reason
reason,
);
return this.scheduler.cancelAll(this.guid, cancelRequest).then(() => {
if (resetState) {
Expand Down
Loading

0 comments on commit ad03181

Please sign in to comment.