Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: compile linked TS plugins #573

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@oclif/core",
"description": "base library for oclif CLIs",
"version": "1.21.0",
"version": "2.0.0",
"author": "Salesforce",
"bugs": "https://github.com/oclif/core/issues",
"dependencies": {
Expand Down
1 change: 0 additions & 1 deletion src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ try {

export {Config, toCached} from './config'
export {Plugin} from './plugin'
export {tsPath} from './ts-node'

17 changes: 14 additions & 3 deletions src/config/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {error} from '../errors'
import * as Globby from 'globby'
import * as path from 'path'
import {inspect} from 'util'
import {inspect, promisify} from 'util'

import {Plugin as IPlugin, PluginOptions} from '../interfaces/plugin'
import {Command} from '../interfaces/command'
Expand All @@ -10,7 +10,6 @@ import {Debug} from './util'
import {Manifest} from '../interfaces/manifest'
import {PJSON} from '../interfaces/pjson'
import {Topic} from '../interfaces/topic'
import {tsPath} from './ts-node'
import {compact, exists, resolvePackage, flatMap, loadJSON, mapValues} from './util'
import {isProd} from '../util'
import ModuleLoader from '../module-loader'
Expand Down Expand Up @@ -129,6 +128,8 @@ export class Plugin implements IPlugin {

protected warned = false

private memoizedCommandsDir?: string;

// eslint-disable-next-line no-useless-constructor
constructor(public options: PluginOptions) {}

Expand Down Expand Up @@ -156,7 +157,13 @@ export class Plugin implements IPlugin {

this.hooks = mapValues(this.pjson.oclif.hooks || {}, i => Array.isArray(i) ? i : [i])

if (this.type === 'link' && this.pjson.devDependencies?.typescript) {
// if linked plugin, and project uses TS, we need to compile it
await promisify(require('child_process').exec)('yarn tsc -p . --incremental --skipLibCheck', {cwd: this.root})
}

this.manifest = await this._manifest(Boolean(this.options.ignoreManifest), Boolean(this.options.errorOnManifestCreate))

this.commands = Object
.entries(this.manifest.commands)
.map(([id, c]) => ({...c, pluginAlias: this.alias, pluginType: this.type, load: async () => this.findCommand(id, {must: true})}))
Expand All @@ -168,7 +175,11 @@ export class Plugin implements IPlugin {
}

get commandsDir() {
return tsPath(this.root, this.pjson.oclif.commands)
if (!this.memoizedCommandsDir) {
this.memoizedCommandsDir = this.pjson.oclif.commands ? path.join(this.root, this.pjson.oclif.commands) : undefined
}

return this.memoizedCommandsDir
}

get commandIDs() {
Expand Down
79 changes: 0 additions & 79 deletions src/config/ts-node.ts

This file was deleted.

3 changes: 1 addition & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as semver from 'semver'

import Command from './command'
import {run} from './main'
import {Config, Plugin, tsPath, toCached} from './config'
import {Config, Plugin, toCached} from './config'
import * as Interfaces from './interfaces'
import * as Errors from './errors'
import * as Flags from './flags'
Expand Down Expand Up @@ -35,7 +35,6 @@ export {
Plugin,
run,
toCached,
tsPath,
toStandardizedId,
toConfiguredId,
settings,
Expand Down
1 change: 0 additions & 1 deletion src/interfaces/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,4 @@ export {
export {PJSON} from './pjson'
export {Plugin, PluginOptions, Options} from './plugin'
export {Topic} from './topic'
export {TSConfig} from './ts-config'
export {InferredFlags} from './flags'
1 change: 1 addition & 0 deletions src/interfaces/pjson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {HelpOptions} from './help'
export interface PJSON {
[k: string]: any;
dependencies?: {[name: string]: string};
devDependencies?: {[name: string]: string};
oclif: {
schema?: number;
};
Expand Down
11 changes: 0 additions & 11 deletions src/interfaces/ts-config.ts

This file was deleted.

5 changes: 2 additions & 3 deletions src/module-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import * as fs from 'fs-extra'
import {ModuleLoadError} from './errors'
import {Config as IConfig} from './interfaces'
import {Plugin as IPlugin} from './interfaces'
import * as Config from './config'

const getPackageType = require('get-package-type')

Expand Down Expand Up @@ -123,7 +122,7 @@ export default class ModuleLoader {

/**
* Resolves a modulePath first by `require.resolve` to allow Node to resolve an actual module. If this fails then
* the `modulePath` is resolved from the root of the provided config. `Config.tsPath` is used for initial resolution.
* the `modulePath` is resolved from the root of the provided config.
* If this file path does not exist then several extensions are tried from `s_EXTENSIONS` in order: '.js', '.mjs',
* '.cjs'. After a file path has been selected `isPathModule` is used to determine if the file is an ES Module.
*
Expand All @@ -140,7 +139,7 @@ export default class ModuleLoader {
filePath = require.resolve(modulePath)
isESM = ModuleLoader.isPathModule(filePath)
} catch {
filePath = Config.tsPath(config.root, modulePath)
filePath = path.join(config.root, modulePath)

let fileExists = false
let isDirectory = false
Expand Down
12 changes: 1 addition & 11 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,7 @@ export type Settings = {
* OCLIF_COLUMNS=80
*/
columns?: number;
/**
* Try to use ts-node to load typescript source files instead of
* javascript files.
*
* NOTE: This requires registering ts-node first.
* require('ts-node').register();
*
* Environment Variable:
* NODE_ENV=development
*/
tsnodeEnabled?: boolean;

};

// Set global.oclif to the new object if it wasn't set before
Expand Down
94 changes: 0 additions & 94 deletions test/config/ts-node.test.ts

This file was deleted.

6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -856,9 +856,9 @@ acorn@^7.4.0:
integrity sha512-nQyp0o1/mNdbTO1PO6kHkwSrmgZ0MT/jCCpNiwbUjGoRN4dlBhqJtoQuCnEOKzgTVwg0ZWiCoQy6SxMebQVh8A==

acorn@^8.4.1:
version "8.8.0"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.8.0.tgz#88c0187620435c7f6015803f5539dae05a9dbea8"
integrity sha512-QOxyigPVrpZ2GXT+PFyZTl6TtOFc5egxHIP9IlQ+RbupQuX4RkT/Bee4/kQuC02Xkzg84JcT7oLYtDIQxp+v7w==
version "8.8.1"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.8.1.tgz#0a3f9cbecc4ec3bea6f0a80b66ae8dd2da250b73"
integrity sha512-7zFpHzhnqYKrkYdUjF1HI1bzd0VygEGX8lFk4k5zVMqHEoES+P+7TKI+EvLO9WVMJ8eekdO0aDEK044xTXwPPA==

ajv@^6.10.0, ajv@^6.12.4:
version "6.12.6"
Expand Down