Skip to content

Commit

Permalink
Merge branch 'master' into const-definition
Browse files Browse the repository at this point in the history
  • Loading branch information
TwitchBronBron committed Jul 29, 2022
2 parents 330f8d8 + f1a1f93 commit bb194bc
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 20 deletions.
13 changes: 12 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
"@types/marked": "^4.0.3",
"@types/mocha": "^5.2.5",
"@types/node": "^11.9.0",
"@types/require-relative": "^0.8.0",
"@types/sinon": "^9.0.4",
"@types/turndown": "^5.0.1",
"@types/yargs": "^15.0.5",
Expand Down Expand Up @@ -139,6 +140,7 @@
"moment": "^2.23.0",
"p-settle": "^2.1.0",
"parse-ms": "^2.1.0",
"require-relative": "^0.8.7",
"roku-deploy": "^3.7.1",
"serialize-error": "^7.0.1",
"source-map": "^0.7.3",
Expand Down
3 changes: 2 additions & 1 deletion src/ProgramBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { Logger, LogLevel } from './Logger';
import PluginInterface from './PluginInterface';
import * as diagnosticUtils from './diagnosticUtils';
import * as fsExtra from 'fs-extra';
import * as requireRelative from 'require-relative';

/**
* A runner class that handles
Expand Down Expand Up @@ -160,7 +161,7 @@ export class ProgramBuilder {
*/
protected loadRequires() {
for (const dep of this.options.require ?? []) {
util.resolveRequire(this.options.cwd, dep);
requireRelative(dep, this.options.cwd);
}
}

Expand Down
20 changes: 2 additions & 18 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { WalkMode } from './astUtils/visitors';
import { CustomType } from './types/CustomType';
import { SourceNode } from 'source-map';
import type { SGAttribute } from './parser/SGTypes';
import * as requireRelative from 'require-relative';

export class Util {
public clearConsole() {
Expand Down Expand Up @@ -1096,7 +1097,7 @@ export class Util {
return pathOrModules.reduce<CompilerPlugin[]>((acc, pathOrModule) => {
if (typeof pathOrModule === 'string') {
try {
const loaded = this.resolveRequire(cwd, pathOrModule);
const loaded = requireRelative(pathOrModule, cwd);
const theExport: CompilerPlugin | CompilerPluginFactory = loaded.default ? loaded.default : loaded;

let plugin: CompilerPlugin;
Expand Down Expand Up @@ -1127,23 +1128,6 @@ export class Util {
}, []);
}

public resolveRequire(cwd: string, pathOrModule: string) {
let target = pathOrModule;
if (!path.isAbsolute(pathOrModule)) {
const localPath = path.resolve(cwd, pathOrModule);
if (fs.existsSync(localPath)) {
target = localPath;
} else {
const modulePath = path.resolve(cwd, 'node_modules', pathOrModule);
if (fs.existsSync(modulePath)) {
target = modulePath;
}
}
}
// eslint-disable-next-line
return require(target);
}

/**
* Gathers expressions, variables, and unique names from an expression.
* This is mostly used for the ternary expression
Expand Down

0 comments on commit bb194bc

Please sign in to comment.