From b3e3940d7391189d8032cf58ca8a129911e55cf7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20P=C3=A9rez=20Manr=C3=ADquez?= Date: Thu, 29 Sep 2022 11:16:57 -0300 Subject: [PATCH 1/4] Paves the way for deno --- package.json | 1 + src/config/plugin.ts | 31 ++++++++++++++++++++++--------- src/config/util.ts | 11 ++++++++--- src/interfaces/pjson.ts | 4 ++++ yarn.lock | 5 +++++ 5 files changed, 40 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index bf0c409c2..4f7e8f6c3 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,7 @@ "indent-string": "^4.0.0", "is-wsl": "^2.2.0", "js-yaml": "^3.14.1", + "json5": "^2.2.1", "natural-orderby": "^2.0.3", "object-treeify": "^1.1.33", "password-prompt": "^1.1.2", diff --git a/src/config/plugin.ts b/src/config/plugin.ts index 9e69b002b..b4bc1d61b 100644 --- a/src/config/plugin.ts +++ b/src/config/plugin.ts @@ -17,6 +17,9 @@ import ModuleLoader from '../module-loader' const _pjson = require('../../package.json') +const PACKAGE_JSON = 'package.json' +const DENO_JSON = 'deno.jsonc' + function topicsToArray(input: any, base?: string): Topic[] { if (!input) return [] base = base ? `${base}:` : '' @@ -40,9 +43,9 @@ function * up(from: string) { yield from } -async function findSourcesRoot(root: string) { +async function findSourcesRoot(root: string, configFile: string) { for (const next of up(root)) { - const cur = path.join(next, 'package.json') + const cur = path.join(next, configFile) // eslint-disable-next-line no-await-in-loop if (await exists(cur)) return path.dirname(cur) } @@ -79,17 +82,17 @@ async function findRootLegacy(name: string | undefined, root: string): Promise { +export function loadJSON(_path: string): Promise { debug('config')('loadJSON %s', path) + // Allows reading JSON with comments + const _JSON = path.extname(_path) === '.jsonc' ? JSON5 : JSON return new Promise((resolve, reject) => { - fs.readFile(path, 'utf8', (err: any, d: any) => { + fs.readFile(_path, 'utf8', (err: any, d: any) => { try { if (err) reject(err) - else resolve(JSON.parse(d)) + const obj = _JSON.parse(d) + resolve(obj) } catch (error: any) { reject(error) } diff --git a/src/interfaces/pjson.ts b/src/interfaces/pjson.ts index bb7285b15..4eb1f83c7 100644 --- a/src/interfaces/pjson.ts +++ b/src/interfaces/pjson.ts @@ -36,6 +36,10 @@ export namespace PJSON { version?: string; targets?: string[]; }; + deno?: { + version?: string; + targets?: string[]; + }; }; topics?: { [k: string]: { diff --git a/yarn.lock b/yarn.lock index 43a20535f..1e83631c0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2249,6 +2249,11 @@ json5@^2.1.2: dependencies: minimist "^1.2.5" +json5@^2.2.1: + version "2.2.1" + resolved "https://registry.yarnpkg.com/json5/-/json5-2.2.1.tgz#655d50ed1e6f95ad1a3caababd2b0efda10b395c" + integrity sha512-1hqLFMSrGHRHxav9q9gNjJ5EXznIxGVO09xQRrwplcS8qs28pZ8s8hupZAmqDwZUmVZ2Qb2jnyPOWcDH8m8dlA== + jsonfile@^6.0.1: version "6.1.0" resolved "https://registry.yarnpkg.com/jsonfile/-/jsonfile-6.1.0.tgz#bc55b2634793c679ec6403094eb13698a6ec0aae" From eb3778555614ddc0018521723d97d2d31d529956 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20P=C3=A9rez=20Manr=C3=ADquez?= Date: Thu, 29 Sep 2022 12:00:11 -0300 Subject: [PATCH 2/4] adds findRootConfigFile --- src/config/plugin.ts | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/src/config/plugin.ts b/src/config/plugin.ts index b4bc1d61b..28acf6174 100644 --- a/src/config/plugin.ts +++ b/src/config/plugin.ts @@ -43,11 +43,16 @@ function * up(from: string) { yield from } -async function findSourcesRoot(root: string, configFile: string) { +// Looks for a node or a deno root config file. +// Which is ever is closest up in the directory tree. +async function findSourcesRoot(root: string) { for (const next of up(root)) { - const cur = path.join(next, configFile) + const nodeConfigFile = path.join(next, PACKAGE_JSON) + const denoConfigFile = path.join(next, DENO_JSON) // eslint-disable-next-line no-await-in-loop - if (await exists(cur)) return path.dirname(cur) + if (await exists(nodeConfigFile)) return path.dirname(nodeConfigFile) + // eslint-disable-next-line no-await-in-loop + if (await exists(denoConfigFile)) return path.dirname(denoConfigFile) } } @@ -82,17 +87,22 @@ async function findRootLegacy(name: string | undefined, root: string): Promise Date: Thu, 29 Sep 2022 12:04:34 -0300 Subject: [PATCH 3/4] Cleans findSourcesRoot --- src/config/plugin.ts | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/config/plugin.ts b/src/config/plugin.ts index 28acf6174..b95cb013b 100644 --- a/src/config/plugin.ts +++ b/src/config/plugin.ts @@ -43,16 +43,14 @@ function * up(from: string) { yield from } -// Looks for a node or a deno root config file. -// Which is ever is closest up in the directory tree. +// Finds the root dir based on a node or a deno root config file, +// which ever is closest up in the directory tree. async function findSourcesRoot(root: string) { for (const next of up(root)) { const nodeConfigFile = path.join(next, PACKAGE_JSON) const denoConfigFile = path.join(next, DENO_JSON) // eslint-disable-next-line no-await-in-loop - if (await exists(nodeConfigFile)) return path.dirname(nodeConfigFile) - // eslint-disable-next-line no-await-in-loop - if (await exists(denoConfigFile)) return path.dirname(denoConfigFile) + if (await exists(nodeConfigFile) || await exists(denoConfigFile)) return path.dirname(nodeConfigFile) } } @@ -149,7 +147,7 @@ export class Plugin implements IPlugin { this.type = this.options.type || 'core' this.tag = this.options.tag const root = await findRoot(this.options.name, this.options.root) - if (!root) throw new Error(`could not find package.json with options: ${inspect(this.options)}`) + if (!root) throw new Error(`could not find package.json with ${inspect(this.options)}`) const rootConfigFile = await findRootConfigFile(root) if (!rootConfigFile) throw new Error(`could not find ${rootConfigFile} in ${root}`) this.root = root From 032a0f9b9399ec24c04287e91c72b1898edbb051 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20P=C3=A9rez=20Manr=C3=ADquez?= Date: Wed, 16 Nov 2022 14:40:55 -0300 Subject: [PATCH 4/4] v16.6.7 --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 4f7e8f6c3..7bfd1d489 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { - "name": "@oclif/core", + "name": "oclif-core-rc", "description": "base library for oclif CLIs", - "version": "1.16.4", + "version": "16.6.7", "author": "Salesforce", "bugs": "https://github.com/oclif/core/issues", "dependencies": {