Skip to content

Commit

Permalink
fix(cli): fix require error issue related to update-notifier import
Browse files Browse the repository at this point in the history
Closes: #392
  • Loading branch information
Romakita committed Jul 25, 2024
1 parent 4a7dc55 commit 619fcc2
Show file tree
Hide file tree
Showing 12 changed files with 53 additions and 70 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
"@swc/helpers": "^0.5.1",
"@swc/jest": "^0.2.26",
"@tsed/markdown-it-symbols": "3.20.4",
"@tsed/monorepo-utils": "2.1.2",
"@tsed/monorepo-utils": "2.2.2",
"@tsed/ts-doc": "^4.1.0",
"@types/jest": "28.1.7",
"@types/node": "18.7.8",
Expand Down
1 change: 0 additions & 1 deletion packages/cli-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
"enquirer": "2.3.6",
"execa": "5.1.1",
"figures": "4.0.1",
"filedirname": "2.7.0",
"fs-extra": "11.1.0",
"globby": "11.1.0",
"handlebars": "4.7.7",
Expand Down
3 changes: 2 additions & 1 deletion packages/cli-core/src/interfaces/Tasks.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {ListrContext, ListrOptions, ListrTask} from "listr2";
// @ts-ignore
import type {ListrContext, ListrOptions, ListrTask} from "listr2";

export interface TaskOptions<Ctx = ListrContext> extends ListrOptions<Ctx> {
concurrent?: boolean | number;
Expand Down
3 changes: 2 additions & 1 deletion packages/cli-core/src/services/CliPlugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {CliHooks} from "./CliHooks";
import {NpmRegistryClient} from "./NpmRegistryClient";
import {ProjectPackageJson} from "./ProjectPackageJson";
import {PackageManagersModule} from "../packageManagers/PackageManagersModule";
import {Task} from "../interfaces";

function mapPlugins({package: {name, description = "", ...otherProps}}: any) {
return {
Expand Down Expand Up @@ -46,7 +47,7 @@ export class CliPlugins {
return loadPlugins(this.injector);
}

addPluginsDependencies(ctx: any) {
addPluginsDependencies(ctx: any): Task[] {
const plugins = Object.keys(this.packageJson.devDependencies).filter((name) => this.isPlugin(name));

const tasks = plugins.map((plugin) => {
Expand Down
3 changes: 1 addition & 2 deletions packages/cli-core/src/services/ProjectPackageJson.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import {CliPlatformTest} from "@tsed/cli-testing";
import {join, resolve} from "path";
import filedirname from "filedirname";
import {ProjectPackageJson} from "./ProjectPackageJson";
import {CliFs} from "./CliFs";
import {CliExeca} from "./CliExeca";

const [, dir] = filedirname();
const dir = __dirname;

async function getProjectPackageJsonFixture() {
const cliFs = {
Expand Down
1 change: 1 addition & 0 deletions packages/cli-core/src/utils/createTasksRunner.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-ignore
import {Listr, ListrTaskWrapper, Logger} from "listr2";
import type {TaskOptions, Tasks} from "../interfaces/Tasks";
import {isFunction} from "@tsed/core";
Expand Down
1 change: 0 additions & 1 deletion packages/cli-core/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@ export * from "./parseOption";
export * from "./createTasksRunner";
export * from "./resolveConfiguration";
export * from "./getTemplateDirectory";
export {default as filedirname} from "filedirname";
1 change: 1 addition & 0 deletions packages/cli-core/src/utils/loadPlugins.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {GlobalProviders, InjectorService} from "@tsed/di";
// @ts-ignore
import {figures} from "listr2";
import chalk from "chalk";
import {CliFs} from "../services/CliFs";
Expand Down
1 change: 1 addition & 0 deletions packages/cli-core/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"compilerOptions": {
"baseUrl": ".",
"module": "commonjs",
"moduleResolution": "Node16",
"rootDir": "src",
"outDir": "./lib/cjs",
"declaration": true,
Expand Down
1 change: 0 additions & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@
"@tsed/schema": ">=7.14.2",
"chalk": "4.1.2",
"change-case": "4.1.2",
"filedirname": "2.7.0",
"globby": "11.1.0",
"module-alias": "^2.2.2",
"normalize-path": "3.0.0",
Expand Down
78 changes: 39 additions & 39 deletions packages/cli/test/integrations/init/init.integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ import {CliPlatformTest, FakeCliFs} from "@tsed/cli-testing";
import {ensureDirSync, writeFileSync} from "fs-extra";
import {join} from "path";
import {ArchitectureConvention, InitCmd, ProjectConvention, TEMPLATE_DIR} from "../../../src";
import filedirname from "filedirname";

const [, dir] = filedirname();
const dir = __dirname

describe("Init cmd", () => {
beforeEach(() => {
Expand Down Expand Up @@ -66,9 +65,9 @@ describe("Init cmd", () => {
`);

const content = FakeCliFs.entries.get("project-name/src/Server.ts")!;
expect(content).toContain('import {Configuration, Inject} from "@tsed/di"');
expect(content).toContain('import "@tsed/platform-express"');
expect(content).toContain('import "@tsed/ajv"');
expect(content).toContain("import {Configuration, Inject} from \"@tsed/di\"");
expect(content).toContain("import \"@tsed/platform-express\"");
expect(content).toContain("import \"@tsed/ajv\"");
expect(content).toMatchSnapshot();

const pkg = JSON.parse(FakeCliFs.entries.get("project-name/package.json")!);
Expand Down Expand Up @@ -116,7 +115,7 @@ describe("Init cmd", () => {
expect(dockerFile).toContain("RUN yarn install --pure-lockfile");

const indexContent = FakeCliFs.entries.get("project-name/src/index.ts")!;
expect(indexContent).toContain('import {Server} from "./Server"');
expect(indexContent).toContain("import {Server} from \"./Server\"");
});
it("should generate a project with swagger", async () => {
CliPlatformTest.setPackageJson({
Expand Down Expand Up @@ -170,10 +169,10 @@ describe("Init cmd", () => {

const content = FakeCliFs.entries.get("project-name/src/Server.ts")!;

expect(content).toContain('import {Configuration, Inject} from "@tsed/di"');
expect(content).toContain('import "@tsed/platform-express"');
expect(content).toContain('import "@tsed/ajv"');
expect(content).toContain('import * as pages from "./controllers/pages/index"');
expect(content).toContain("import {Configuration, Inject} from \"@tsed/di\"");
expect(content).toContain("import \"@tsed/platform-express\"");
expect(content).toContain("import \"@tsed/ajv\"");
expect(content).toContain("import * as pages from \"./controllers/pages/index\"");
expect(content).toMatchSnapshot();

const pkg = JSON.parse(FakeCliFs.entries.get("project-name/package.json")!);
Expand Down Expand Up @@ -261,9 +260,9 @@ describe("Init cmd", () => {
`);

const content = FakeCliFs.entries.get("project-name/src/Server.ts")!;
expect(content).toContain('import {Configuration, Inject} from "@tsed/di"');
expect(content).toContain('import "@tsed/platform-express"');
expect(content).toContain('import "@tsed/ajv"');
expect(content).toContain("import {Configuration, Inject} from \"@tsed/di\"");
expect(content).toContain("import \"@tsed/platform-express\"");
expect(content).toContain("import \"@tsed/ajv\"");
expect(content).toMatchSnapshot();

const pkg = JSON.parse(FakeCliFs.entries.get("project-name/package.json")!);
Expand Down Expand Up @@ -352,9 +351,9 @@ describe("Init cmd", () => {
`);

const content = FakeCliFs.entries.get("project-name/src/Server.ts")!;
expect(content).toContain('import {Configuration, Inject} from "@tsed/di"');
expect(content).toContain('import "@tsed/platform-express"');
expect(content).toContain('import "@tsed/ajv"');
expect(content).toContain("import {Configuration, Inject} from \"@tsed/di\"");
expect(content).toContain("import \"@tsed/platform-express\"");
expect(content).toContain("import \"@tsed/ajv\"");
expect(content).toMatchSnapshot();

const pkg = JSON.parse(FakeCliFs.entries.get("project-name/package.json")!);
Expand Down Expand Up @@ -444,9 +443,9 @@ describe("Init cmd", () => {
`);

const content = FakeCliFs.entries.get("project-name/src/Server.ts")!;
expect(content).toContain('import {Configuration, Inject} from "@tsed/di"');
expect(content).toContain('import "@tsed/platform-express"');
expect(content).toContain('import "@tsed/ajv"');
expect(content).toContain("import {Configuration, Inject} from \"@tsed/di\"");
expect(content).toContain("import \"@tsed/platform-express\"");
expect(content).toContain("import \"@tsed/ajv\"");
expect(content).toMatchSnapshot();

const pkg = JSON.parse(FakeCliFs.entries.get("project-name/package.json")!);
Expand Down Expand Up @@ -536,9 +535,9 @@ describe("Init cmd", () => {
`);

const content = FakeCliFs.entries.get("project-name/src/Server.ts")!;
expect(content).toContain('import {Configuration, Inject} from "@tsed/di"');
expect(content).toContain('import "@tsed/platform-express"');
expect(content).toContain('import "@tsed/ajv"');
expect(content).toContain("import {Configuration, Inject} from \"@tsed/di\"");
expect(content).toContain("import \"@tsed/platform-express\"");
expect(content).toContain("import \"@tsed/ajv\"");
expect(content).toMatchSnapshot();

const pkg = JSON.parse(FakeCliFs.entries.get("project-name/package.json")!);
Expand Down Expand Up @@ -626,9 +625,9 @@ describe("Init cmd", () => {
`);

const content = FakeCliFs.entries.get("project-name/src/Server.ts")!;
expect(content).toContain('import {Configuration, Inject} from "@tsed/di"');
expect(content).toContain('import "@tsed/platform-express"');
expect(content).toContain('import "@tsed/ajv"');
expect(content).toContain("import {Configuration, Inject} from \"@tsed/di\"");
expect(content).toContain("import \"@tsed/platform-express\"");
expect(content).toContain("import \"@tsed/ajv\"");
expect(content).toMatchSnapshot();

const pkg = JSON.parse(FakeCliFs.entries.get("project-name/package.json")!);
Expand Down Expand Up @@ -724,15 +723,15 @@ describe("Init cmd", () => {
`);

const content = FakeCliFs.entries.get("project-name/src/server.ts")!;
expect(content).toContain('import {Configuration, Inject} from "@tsed/di"');
expect(content).toContain('import "@tsed/platform-express"');
expect(content).toContain('import "@tsed/ajv"');
expect(content).toContain("import {Configuration, Inject} from \"@tsed/di\"");
expect(content).toContain("import \"@tsed/platform-express\"");
expect(content).toContain("import \"@tsed/ajv\"");
expect(content).toMatchSnapshot();
expect(content).toContain('import * as pages from "./controllers/pages/index"');
expect(content).toContain("import * as pages from \"./controllers/pages/index\"");
expect(content).toContain("export class Server {");

const indexContent = FakeCliFs.entries.get("project-name/src/index.ts")!;
expect(indexContent).toContain('import {Server} from "./server"');
expect(indexContent).toContain("import {Server} from \"./server\"");
});
it("should generate a project with Arch FEATURE", async () => {
CliPlatformTest.setPackageJson({
Expand Down Expand Up @@ -788,15 +787,15 @@ describe("Init cmd", () => {
`);

const content = FakeCliFs.entries.get("project-name/src/server.ts")!;
expect(content).toContain('import {Configuration, Inject} from "@tsed/di"');
expect(content).toContain('import "@tsed/platform-express"');
expect(content).toContain('import "@tsed/ajv"');
expect(content).toContain("import {Configuration, Inject} from \"@tsed/di\"");
expect(content).toContain("import \"@tsed/platform-express\"");
expect(content).toContain("import \"@tsed/ajv\"");
expect(content).toMatchSnapshot();
expect(content).toContain('import * as pages from "./pages/index"');
expect(content).toContain("import * as pages from \"./pages/index\"");
expect(content).toContain("export class Server {");

const indexContent = FakeCliFs.entries.get("project-name/src/index.ts")!;
expect(indexContent).toContain('import {Server} from "./server"');
expect(indexContent).toContain("import {Server} from \"./server\"");
});
});

Expand Down Expand Up @@ -848,9 +847,9 @@ describe("Init cmd", () => {

const content = FakeCliFs.entries.get("project-name/src/Server.ts")!;

expect(content).toContain('import {Configuration, Inject} from "@tsed/di"');
expect(content).toContain('import "@tsed/platform-koa"');
expect(content).toContain('import "@tsed/ajv"');
expect(content).toContain("import {Configuration, Inject} from \"@tsed/di\"");
expect(content).toContain("import \"@tsed/platform-koa\"");
expect(content).toContain("import \"@tsed/ajv\"");
expect(content).toMatchSnapshot();

const pkg = JSON.parse(FakeCliFs.entries.get("project-name/package.json")!);
Expand Down Expand Up @@ -921,7 +920,8 @@ describe("Init cmd", () => {
ensureDirSync(join(dir, "data", key));
}
});
} catch (er) {}
} catch (er) {
}

expect(FakeCliFs.getKeys()).toMatchInlineSnapshot(`
Array [
Expand Down
28 changes: 5 additions & 23 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3277,7 +3277,6 @@ __metadata:
eslint: "npm:8.22.0"
execa: "npm:5.1.1"
figures: "npm:4.0.1"
filedirname: "npm:2.7.0"
fs-extra: "npm:11.1.0"
globby: "npm:11.1.0"
handlebars: "npm:4.7.7"
Expand Down Expand Up @@ -3543,7 +3542,7 @@ __metadata:
"@tsed/di": "npm:>=7.14.2"
"@tsed/logger": "npm:>=6.2.1"
"@tsed/markdown-it-symbols": "npm:3.20.4"
"@tsed/monorepo-utils": "npm:2.1.2"
"@tsed/monorepo-utils": "npm:2.2.2"
"@tsed/normalize-path": "npm:>=7.14.2"
"@tsed/ts-doc": "npm:^4.1.0"
"@types/jest": "npm:28.1.7"
Expand Down Expand Up @@ -3635,7 +3634,6 @@ __metadata:
change-case: "npm:4.1.2"
cross-env: "npm:7.0.3"
eslint: "npm:8.22.0"
filedirname: "npm:2.7.0"
globby: "npm:11.1.0"
jest: "npm:29.5.0"
module-alias: "npm:^2.2.2"
Expand Down Expand Up @@ -3723,9 +3721,9 @@ __metadata:
languageName: node
linkType: hard

"@tsed/monorepo-utils@npm:2.1.2":
version: 2.1.2
resolution: "@tsed/monorepo-utils@npm:2.1.2"
"@tsed/monorepo-utils@npm:2.2.2":
version: 2.2.2
resolution: "@tsed/monorepo-utils@npm:2.2.2"
dependencies:
"@samverschueren/stream-to-observable": "npm:>=0.3.1"
"@typescript-eslint/typescript-estree": "npm:>=6.20.0"
Expand All @@ -3752,7 +3750,7 @@ __metadata:
semantic-release: ">=19"
bin:
monorepo: bin/monorepo.js
checksum: 10/839fdd5a50e893a61f2bfdabec82296504bd5b060fe6211ed6e591e473b9979b3a4c4b7eba427e836d54bee0788c89d56fe72e5088d70e5acaa22305958fb21f
checksum: 10/854af44cf89137c2586efb2f2c24b965f4da6e14fc0a45f0e46b42451642ee32712d10ccea17fb58e54bdc9a2731d547cd715ec464d94167eaa6c9c9c72669f3
languageName: node
linkType: hard

Expand Down Expand Up @@ -8432,15 +8430,6 @@ __metadata:
languageName: node
linkType: hard

"filedirname@npm:2.7.0":
version: 2.7.0
resolution: "filedirname@npm:2.7.0"
dependencies:
get-current-line: "npm:^6.5.0"
checksum: 10/a32e2c1005ac8a3706cda47819ebff1100d5892e986e73c311da7ca80679143ada01d9536ef42c10af0ec076a616ae390b5f30c332f373fd4fb483731f41148e
languageName: node
linkType: hard

"fill-range@npm:^4.0.0":
version: 4.0.0
resolution: "fill-range@npm:4.0.0"
Expand Down Expand Up @@ -8829,13 +8818,6 @@ __metadata:
languageName: node
linkType: hard

"get-current-line@npm:^6.5.0":
version: 6.6.0
resolution: "get-current-line@npm:6.6.0"
checksum: 10/bff44a3b3b5469dae1ab5b87adfe88d8149379b35069f6902eff3e779e1996e5464a106d2d542f1c89cd02e17fe513e4ca30e5910a59877d0588631da4ac1f48
languageName: node
linkType: hard

"get-east-asian-width@npm:^1.0.0":
version: 1.2.0
resolution: "get-east-asian-width@npm:1.2.0"
Expand Down

0 comments on commit 619fcc2

Please sign in to comment.