Skip to content

Commit

Permalink
bump required environment to 4.0.0-rc.0 and node 18.12.0 (#1478)
Browse files Browse the repository at this point in the history
* rework queueTransformStream

* bump dependencies.

* bump dependencies

* bump dependencies

* bump dependencies.

* add @types/minimist devDependency

* bump environment requirement
  • Loading branch information
mshima committed Oct 16, 2023
1 parent be9415d commit 9bc9b16
Show file tree
Hide file tree
Showing 11 changed files with 4,329 additions and 4,584 deletions.
8,712 changes: 4,208 additions & 4,504 deletions package-lock.json

Large diffs are not rendered by default.

55 changes: 28 additions & 27 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,52 +51,53 @@
"doc_path": "../yeoman-generator-doc/"
},
"dependencies": {
"@types/lodash-es": "^4.17.7",
"@types/node": "^16.18.3",
"@types/lodash-es": "^4.17.9",
"@types/node": "^18.18.5",
"@yeoman/namespace": "^1.0.0",
"chalk": "^5.1.2",
"chalk": "^5.3.0",
"debug": "^4.1.1",
"execa": "^8.0.1",
"github-username": "^7.0.0",
"json-schema": "^0.4.0",
"latest-version": "^7.0.0",
"lodash-es": "^4.17.21",
"mem-fs-editor": "^10.0.1",
"mem-fs-editor": "^11.0.0",
"minimist": "^1.2.8",
"read-pkg-up": "^10.1.0",
"semver": "^7.5.0",
"simple-git": "^3.18.0",
"semver": "^7.5.4",
"simple-git": "^3.20.0",
"sort-keys": "^5.0.0",
"text-table": "^0.2.0"
},
"devDependencies": {
"@types/debug": "^4.1.7",
"@types/inquirer": "^9.0.3",
"@types/semver": "^7.3.13",
"@types/sinon": "^10.0.14",
"@types/text-table": "^0.2.2",
"@yeoman/adapter": "^1.1.0",
"@yeoman/transform": "^1.1.0",
"c8": "^8.0.0",
"cpy-cli": "^4.2.0",
"@types/debug": "^4.1.9",
"@types/inquirer": "^9.0.4",
"@types/minimist": "^1.2.3",
"@types/semver": "^7.5.3",
"@types/sinon": "^10.0.19",
"@types/text-table": "^0.2.3",
"@yeoman/adapter": "^1.4.0",
"@yeoman/transform": "^1.2.0",
"c8": "^8.0.1",
"cpy-cli": "^5.0.0",
"esmocha": "^1.0.1",
"inquirer": "^9.2.1",
"inquirer": "^9.2.11",
"jsdoc": "^4.0.2",
"mem-fs": "^3.0.0",
"nock": "^13.3.1",
"prettier": "^2.8.8",
"prettier-plugin-packagejson": "^2.4.3",
"sinon": "^15.0.4",
"nock": "^13.3.4",
"prettier": "^3.0.3",
"prettier-plugin-packagejson": "^2.4.6",
"sinon": "^16.1.0",
"tui-jsdoc-template": "^1.2.2",
"typescript": "^5.0.4",
"xo": "^0.54.2",
"typescript": "^5.2.2",
"xo": "^0.56.0",
"yeoman-assert": "^3.1.1",
"yeoman-environment": "^3.18.4",
"yeoman-test": "^8.0.0-rc.0"
"yeoman-environment": "^4.0.0-rc.0",
"yeoman-test": "^8.1.0"
},
"peerDependencies": {
"@yeoman/types": "^1.0.1",
"yeoman-environment": "^3.18.4 || ^4.0.0-alpha.4"
"@yeoman/types": "^1.1.1",
"mem-fs": "^4.0.0",
"yeoman-environment": "^4.0.0-rc.0"
},
"peerDependenciesMeta": {
"yeoman-environment": {
Expand Down
1 change: 0 additions & 1 deletion src/actions/help.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/restrict-template-expressions */
import path from 'node:path';
import fs from 'node:fs';
import table from 'text-table';
Expand Down
52 changes: 40 additions & 12 deletions src/actions/lifecycle.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
/* eslint-disable @typescript-eslint/member-ordering */
import assert from 'node:assert';
import { type Transform } from 'node:stream';
import { dirname, isAbsolute, resolve as pathResolve } from 'node:path';
import { dirname, isAbsolute, resolve as pathResolve, relative } from 'node:path';
import { pathToFileURL } from 'node:url';
import { createRequire } from 'node:module';
import { stat } from 'node:fs/promises';
import createDebug from 'debug';
import type {
ApplyTransformsOptions,
BaseGenerator,
GetGeneratorOptions,
ComposeOptions as EnvironmentComposeOptions,
ProgressOptions,
} from '@yeoman/types';
import { toNamespace } from '@yeoman/namespace';
import { type FileTransform, isFileTransform, type PipelineOptions } from 'mem-fs';
import { type MemFsEditorFile } from 'mem-fs-editor';
// eslint-disable-next-line n/file-extension-in-import
import { isFilePending } from 'mem-fs-editor/state';
import type { Task, TaskOptions, BaseOptions, Priority, ComposeOptions } from '../types.js';
import type Generator from '../index.js';
import type BaseGeneratorImpl from '../generator.js';
Expand Down Expand Up @@ -426,7 +428,7 @@ export abstract class TasksMixin {
* await this.composeWith('bootstrap', { sass: true });
*
* @example <caption>Using a direct dependency generator</caption>
* await this.composeWith(path.resolve(__dirname, 'generator-bootstrap/app/main.js'), { sass: true });
* await this.composeWith(path.resolve(_dirname, 'generator-bootstrap/app/main.js'), { sass: true });
*
* @example <caption>Passing a Generator class</caption>
* await this.composeWith({ Generator: MyGenerator, path: '../generator-bootstrap/app/main.js' }, { sass: true });
Expand Down Expand Up @@ -635,10 +637,28 @@ export abstract class TasksMixin {
*/
queueTransformStream(
this: BaseGeneratorImpl,
transformStreams: Transform | Transform[],
options?: ApplyTransformsOptions & { priorityToQueue?: string },
options?: PipelineOptions<MemFsEditorFile> & ProgressOptions & { pendingFiles?: boolean; priorityToQueue?: string },
...transforms: Array<FileTransform<MemFsEditorFile>>
) {
assert(transformStreams, 'expected to receive a transform stream as parameter');
if (isFileTransform(options)) {
transforms = [options, ...transforms];
options = {};
}

let filter: ((file: MemFsEditorFile) => boolean) | undefined;
const {
disabled,
name,
priorityToQueue,
pendingFiles = true,
filter: passedFilter,
...pipelineOptions
} = options ?? {};
if (passedFilter && pendingFiles) {
filter = (file: MemFsEditorFile) => isFilePending(file) && passedFilter(file);
} else {
filter = pendingFiles ? isFilePending : passedFilter;
}

const getQueueForPriority = (priority: string): string => {
const found = this._queues[priority];
Expand All @@ -649,14 +669,22 @@ export abstract class TasksMixin {
return found.queueName ?? found.priorityName;
};

const { priorityToQueue, ...applyTransformOptions } = options ?? {};
const queueName = priorityToQueue ? getQueueForPriority(priorityToQueue) : 'transform';

const { env } = this;
this.queueTask({
method: async () =>
this.env.applyTransforms(
Array.isArray(transformStreams) ? transformStreams : [transformStreams],
applyTransformOptions,
this.env.adapter.progress(
async ({ step }) =>
env.sharedFs.pipeline({ filter, ...pipelineOptions }, ...transforms, async function* (
generator: AsyncGenerator<MemFsEditorFile>,
) {
for await (const file of generator) {
step('Completed', relative(env.logCwd, file.path));
yield file;
}
} as any),
{ disabled, name },
),
taskName: 'transformStream',
queueName,
Expand Down
2 changes: 1 addition & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// eslint-disable-next-line @typescript-eslint/naming-convention
export const DESTINATION_ROOT_CHANGE_EVENT = 'destinationRootChange';

export const requiredEnvironmentVersion = '3.18.4';
export const requiredEnvironmentVersion = '4.0.0-rc.0';
13 changes: 7 additions & 6 deletions src/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import minimist from 'minimist';
import createDebug from 'debug';
import { type MemFsEditor, create as createMemFsEditor } from 'mem-fs-editor';
import { type YeomanNamespace, requireNamespace, toNamespace } from '@yeoman/namespace';
import type { BaseEnvironment, BaseGenerator as GeneratorApi, Logger } from '@yeoman/types';
import type { BaseEnvironment, BaseGenerator as GeneratorApi, Logger, QueuedAdapter } from '@yeoman/types';
import type { ArgumentSpec, BaseOptions, BaseFeatures, CliOptionSpec, Priority } from './types.js';
import type { PromptAnswers, PromptQuestion, PromptQuestions, QuestionRegistrationOptions } from './questions.js';
import Storage, { type StorageOptions } from './util/storage.js';
Expand All @@ -24,20 +24,21 @@ import { SpawnCommandMixin } from './actions/spawn-command.js';
import { GitMixin } from './actions/user.js';
import { TasksMixin } from './actions/lifecycle.js';

type Environment = BaseEnvironment & { resolvePackage: any };
type Environment = BaseEnvironment<QueuedAdapter> & { resolvePackage: any };

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const _filename = fileURLToPath(import.meta.url);
const _dirname = dirname(_filename);

// eslint-disable-next-line @typescript-eslint/naming-convention
const EMPTY = '@@_YEOMAN_EMPTY_MARKER_@@';
// eslint-disable-next-line @typescript-eslint/naming-convention
const ENV_VER_WITH_VER_API = '2.9.0';

const packageJson = JSON.parse(readFileSync(pathJoin(__dirname, '../package.json'), 'utf8'));
const packageJson = JSON.parse(readFileSync(pathJoin(_dirname, '../package.json'), 'utf8'));

// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
export class BaseGenerator<O extends BaseOptions = BaseOptions, F extends BaseFeatures = BaseFeatures>
// eslint-disable-next-line unicorn/prefer-event-target
extends EventEmitter
implements Omit<GeneratorApi<O, F>, 'features'>
{
Expand Down Expand Up @@ -815,7 +816,7 @@ export class BaseGenerator<O extends BaseOptions = BaseOptions, F extends BaseFe
*/
determineAppname(): string {
const appName: string = this.packageJson.get('name') ?? path.basename(this.destinationRoot());
return appName.replace(/[^\w\s]+?/g, ' ');
return appName.replaceAll(/[^\w\s]+?/g, ' ');
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export type Priority = QueueOptions & {
*/
export type Task = TaskOptions & {
/** Function to be queued. */
// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents

method: (...args: any[]) => unknown | Promise<unknown>;

/** Name of the task. */
Expand Down

0 comments on commit 9bc9b16

Please sign in to comment.