Skip to content

Commit

Permalink
fix(cli-core): add .at() polyfill for nodejs v14
Browse files Browse the repository at this point in the history
  • Loading branch information
Romakita committed Apr 6, 2022
1 parent 4108b56 commit 63e5362
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
18 changes: 18 additions & 0 deletions packages/cli-core/src/utils/patchCommander.ts
@@ -1,6 +1,24 @@
import chalk from "chalk";
import {Command} from "commander";

function at(n: number) {
// ToInteger() abstract op
n = Math.trunc(n) || 0;
// Allow negative indexing from the end
if (n < 0) n += this.length;
// OOB access is guaranteed to return undefined
if (n < 0 || n >= this.length) return undefined;
// Otherwise, this is just normal property access
return this[n];
}

const TypedArray = Reflect.getPrototypeOf(Int8Array);
for (const C of [Array, String, TypedArray]) {
if (C) {
Object.defineProperty((C as any).prototype, "at", {value: at, writable: true, enumerable: false, configurable: true});
}
}

const helpInformation = Command.prototype.helpInformation;

function colorizeSection(str: any, section: string) {
Expand Down
Expand Up @@ -19,7 +19,7 @@ registerProvider<DataSource>({
async useAsyncFactory(logger: Logger) {
await TestDataSource.initialize();

logger.info('Connected with typeorm to database: Test');
logger.info("Connected with typeorm to database: Test");

return TestDataSource;
},
Expand Down
Expand Up @@ -55,7 +55,7 @@ describe("Generate DataSource", () => {

const datasource = FakeCliFs.entries.get("project-name/src/datasources/TestDatasource.ts");

expect(datasource).toEqual(readFile("data/TestDatasource.ts.txt", datasource!));
expect(datasource).toEqual(readFile("data/TestDatasource.ts.txt", datasource!, false));

const dockerCompose = FakeCliFs.entries.get("project-name/docker-compose.yml");
expect(dockerCompose).toEqual(readFile("data/docker-compose.yml.txt", dockerCompose!, false));
Expand Down

0 comments on commit 63e5362

Please sign in to comment.