Skip to content

Commit

Permalink
Bump mem-fs-editor and mem-fs. (#177)
Browse files Browse the repository at this point in the history
* assign to constant before export

* bump mem-fs and mem-fs-editor

* recreate package-lock

* move mem-fs to dependencies.
  • Loading branch information
mshima committed Apr 18, 2023
1 parent 2b46639 commit 2fb819e
Show file tree
Hide file tree
Showing 7 changed files with 4,139 additions and 12,214 deletions.
16,281 changes: 4,103 additions & 12,178 deletions package-lock.json

Large diffs are not rendered by default.

8 changes: 3 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,14 @@
"doc_path": "../yeoman-test-doc"
},
"devDependencies": {
"@node-loaders/esbuild": "^0.6.0",
"@node-loaders/esbuild": "^0.8.0",
"@types/mocha": "^10.0.0",
"@types/node": "^16.18.19",
"@types/sinon": "^10.0.13",
"coveralls": "^3.1.1",
"husky": "^8.0.2",
"jsdoc": "^3.6.10",
"lint-staged": "^13.0.3",
"mem-fs": "^2.2.1",
"mocha": "^10.1.0",
"mocha-expect-snapshot": "^7.0.0",
"prettier": "^2.2.1",
Expand All @@ -47,17 +46,16 @@
},
"dependencies": {
"@types/inquirer": "^8.2.5",
"@types/mem-fs-editor": "^7.0.2",
"@types/yeoman-environment": "^2.10.8",
"@types/yeoman-generator": "^5.2.11",
"inquirer": "^8.2.5",
"lodash": "^4.17.21",
"mem-fs-editor": "^9.7.0",
"mem-fs": "^3.0.0",
"mem-fs-editor": "^10.0.1",
"sinon": "^14.0.2",
"temp-dir": "^3.0.0"
},
"peerDependencies": {
"mem-fs": "^2.2.1",
"yeoman-environment": "^3.13.0",
"yeoman-generator": "*"
},
Expand Down
4 changes: 3 additions & 1 deletion src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,9 @@ export class YeomanTest {
}
}

export default new YeomanTest();
const defaultHelpers = new YeomanTest();

export default defaultHelpers;

export const createHelpers = options => {
const helpers = new YeomanTest();
Expand Down
20 changes: 10 additions & 10 deletions src/run-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import tempDirectory from 'temp-dir';
import type Generator from 'yeoman-generator';
import type Environment from 'yeoman-environment';
import { type LookupOptions, type Options } from 'yeoman-environment';
import MemFsEditor from 'mem-fs-editor';
import MemFsEditorState from 'mem-fs-editor/lib/state.js';
import MemFs from 'mem-fs';
import { create as createMemFsEditor, type MemFsEditor, type VinylMemFsEditorFile } from 'mem-fs-editor';
// eslint-disable-next-line n/file-extension-in-import
import { resetFileCommitStates } from 'mem-fs-editor/state';
import { create as createMemFs, type Store } from 'mem-fs';

import RunResult, { type RunResultOptions } from './run-result.js';
import defaultHelpers, { type GeneratorConstructor, type Dependency, type YeomanTest } from './helpers.js';
Expand All @@ -38,7 +39,7 @@ export type RunContextSettings = {

autoCleanup?: boolean;

memFs?: MemFs.Store;
memFs?: Store;

/**
* File path to the generator (only used if Generator is a constructor)
Expand All @@ -63,8 +64,8 @@ export class RunContextBase<GeneratorType extends Generator = Generator> extends
readonly envOptions: Environment.Options;
completed = false;
targetDirectory?: string;
editor!: MemFsEditor.Editor;
memFs: MemFs.Store;
editor!: MemFsEditor;
memFs: Store<VinylMemFsEditorFile>;
mockedGeneratorFactory: MockedGeneratorFactory;

protected environmentPromise?: PromiseRunResult<GeneratorType>;
Expand Down Expand Up @@ -129,7 +130,7 @@ export class RunContextBase<GeneratorType extends Generator = Generator> extends
}

this.helpers = helpers;
this.memFs = settings?.memFs ?? MemFs.create();
this.memFs = (settings?.memFs as Store<VinylMemFsEditorFile>) ?? createMemFs();
this.mockedGeneratorFactory = this.helpers.createMockedGenerator as any;
}

Expand Down Expand Up @@ -566,12 +567,11 @@ export class RunContextBase<GeneratorType extends Generator = Generator> extends

if (!this.keepFsState) {
this.memFs.each(file => {
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
delete file[MemFsEditorState.STATE_CLEARED];
resetFileCommitStates(file);
});
}

this.editor = MemFsEditor.create(this.memFs);
this.editor = createMemFsEditor(this.memFs);

for (const onTargetDirectory of this.onTargetDirectoryCallbacks) {
// eslint-disable-next-line no-await-in-loop
Expand Down
10 changes: 5 additions & 5 deletions src/run-result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import assert from 'node:assert';
import { existsSync, readFileSync, rmSync } from 'node:fs';
import path from 'node:path';
import process from 'node:process';
import MemFsEditor, { type Editor } from 'mem-fs-editor';
import { create as createMemFsEditor, type MemFsEditor } from 'mem-fs-editor';

import type { Store } from 'mem-fs';
import type Environment from 'yeoman-environment';
Expand Down Expand Up @@ -50,7 +50,7 @@ export type RunResultOptions<GeneratorType extends Generator> = {
*/
memFs: Store;

fs?: MemFsEditor.Editor;
fs?: MemFsEditor;

/**
* The mocked generators of the context.
Expand All @@ -72,7 +72,7 @@ export default class RunResult<GeneratorType extends Generator = Generator> {
cwd: string;
oldCwd: string;
memFs: Store;
fs: Editor;
fs: MemFsEditor;
mockedGenerators: any;
options: RunResultOptions<GeneratorType>;

Expand All @@ -86,7 +86,7 @@ export default class RunResult<GeneratorType extends Generator = Generator> {
this.cwd = options.cwd ?? process.cwd();
this.oldCwd = options.oldCwd;
this.memFs = options.memFs;
this.fs = this.memFs && MemFsEditor.create(this.memFs);
this.fs = this.memFs && createMemFsEditor(this.memFs);
this.mockedGenerators = options.mockedGenerators || {};
this.options = options;
}
Expand Down Expand Up @@ -192,7 +192,7 @@ export default class RunResult<GeneratorType extends Generator = Generator> {

_readFile(filename, json?: boolean) {
filename = this._fileName(filename);
const file = this.fs ? this.fs.read(filename) : readFileSync(filename, 'utf8');
const file = (this.fs ? this.fs.read(filename) : undefined) ?? readFileSync(filename, 'utf8');

return json ? JSON.parse(file) : file;
}
Expand Down
4 changes: 2 additions & 2 deletions test/run-result-assertions.spec.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import path, { dirname } from 'node:path';
import assert from 'node:assert';
import { fileURLToPath } from 'node:url';
import MemFs from 'mem-fs';
import { create as createMemFs } from 'mem-fs';

import RunResult from '../src/run-result.js';

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

describe('run-result-assertions', () => {
const memFs = MemFs.create();
const memFs = createMemFs();

for (const testFs of [
{
Expand Down
26 changes: 13 additions & 13 deletions test/run-result.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import assert from 'node:assert';
import fs from 'node:fs';
import path from 'node:path';
import process from 'node:process';
import MemFs from 'mem-fs';
import MemFsEditor from 'mem-fs-editor';
import { create as createMemFs } from 'mem-fs';
import { create as createMemFsEditor } from 'mem-fs-editor';
import { stub } from 'sinon';

import RunContext from '../src/run-context.js';
Expand All @@ -30,7 +30,7 @@ describe('run-result', () => {
const options = { memFs, cwd };
let runResult;
before(() => {
runResult = new RunResult(options);
runResult = new RunResult(options as any);
});
it('loads memFs option', () => {
assert.equal(runResult.memFs, memFs);
Expand Down Expand Up @@ -61,8 +61,8 @@ describe('run-result', () => {
let runResult;
let consoleMock;
beforeEach(() => {
const memFs = MemFs.create();
const memFsEditor = MemFsEditor.create(memFs);
const memFs = createMemFs();
const memFsEditor = createMemFsEditor(memFs);
runResult = new RunResult({
memFs,
fs: memFsEditor,
Expand Down Expand Up @@ -96,8 +96,8 @@ describe('run-result', () => {
let runResult;
let consoleMock;
beforeEach(() => {
const memFs = MemFs.create();
const memFsEditor = MemFsEditor.create(memFs);
const memFs = createMemFs();
const memFsEditor = createMemFsEditor(memFs);
runResult = new RunResult({
memFs,
fs: memFsEditor,
Expand All @@ -120,8 +120,8 @@ describe('run-result', () => {
describe('#getSnapshot', () => {
let runResult;
beforeEach(() => {
const memFs = MemFs.create();
const memFsEditor = MemFsEditor.create(memFs);
const memFs = createMemFs();
const memFsEditor = createMemFsEditor(memFs);
runResult = new RunResult({
memFs,
fs: memFsEditor,
Expand All @@ -146,8 +146,8 @@ describe('run-result', () => {
describe('#getSnapshotState', () => {
let runResult;
beforeEach(() => {
const memFs = MemFs.create();
const memFsEditor = MemFsEditor.create(memFs);
const memFs = createMemFs();
const memFsEditor = createMemFsEditor(memFs);
runResult = new RunResult({
memFs,
fs: memFsEditor,
Expand Down Expand Up @@ -249,8 +249,8 @@ describe('run-result', () => {
describe('should proxy methods', () => {
let runResult: RunResult;
beforeEach(() => {
const memFs = MemFs.create();
const memFsEditor = MemFsEditor.create(memFs);
const memFs = createMemFs();
const memFsEditor = createMemFsEditor(memFs);
runResult = new RunResult({
memFs,
fs: memFsEditor,
Expand Down

0 comments on commit 2fb819e

Please sign in to comment.