Skip to content

Commit 558f683

Browse files
committed
fix: Fixed plugin resolution, path flag and bumped libraries
1 parent ef1142e commit 558f683

9 files changed

Lines changed: 40 additions & 42 deletions

File tree

package-lock.json

Lines changed: 13 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"ajv": "^8.12.0",
1313
"ajv-formats": "^3.0.1",
1414
"chalk": "^5.3.0",
15-
"codify-schemas": "^1.0.61",
15+
"codify-schemas": "^1.0.63",
1616
"debug": "^4.3.4",
1717
"ink": "^5",
1818
"ink-form": "^2.0.1",
@@ -38,7 +38,7 @@
3838
"@types/semver": "^7.5.4",
3939
"@types/strip-ansi": "^5.2.1",
4040
"@typescript-eslint/eslint-plugin": "^8.16.0",
41-
"codify-plugin-lib": "^1.0.130",
41+
"codify-plugin-lib": "^1.0.132",
4242
"esbuild": "^0.24.0",
4343
"esbuild-plugin-copy": "^2.1.1",
4444
"eslint": "^8.51.0",
@@ -51,7 +51,7 @@
5151
"shx": "^0.3.3",
5252
"strip-ansi": "^7.1.0",
5353
"tsx": "^4.7.3",
54-
"typescript": "^5",
54+
"typescript": "5.3.3",
5555
"vitest": "^2.1.6"
5656
},
5757
"overrides": {
@@ -103,7 +103,7 @@
103103
"postpack": "shx rm -f oclif.manifest.json",
104104
"pretarball": "../../../scripts/codesign.sh",
105105
"pkg": "tsx ./scripts/pkg.ts",
106-
"notorize": "./scripts/notarize.sh",
106+
"notarize": "./scripts/notarize.sh",
107107
"upload": "./scripts/upload.sh",
108108
"posttest": "npm run lint",
109109
"prepack": "oclif manifest && oclif readme",

src/commands/apply/index.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,6 @@ export default class Apply extends BaseCommand {
1111
'<%= config.bin %> <%= command.id %> --path ~',
1212
]
1313

14-
static flags = {
15-
// flag with a value (-p, --path=VALUE)
16-
path: Flags.string({ char: 'p', description: 'path to project' }),
17-
}
18-
1914
async init(): Promise<void> {
2015
console.log('Running Codify apply...')
2116
return super.init();

src/commands/import.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,6 @@ export default class Import extends BaseCommand {
1111
'<%= config.bin %> <%= command.id %> homebrew nvm',
1212
]
1313

14-
static flags = {
15-
// flag with a value (-p, --path=VALUE)
16-
path: Flags.string({ char: 'p', description: 'path to project' }),
17-
}
18-
19-
2014
public async run(): Promise<void> {
2115
const { raw, flags } = await this.parse(Import)
2216

src/commands/plan/index.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@ export default class Plan extends BaseCommand {
1212
'<%= config.bin %> <%= command.id %>',
1313
]
1414

15-
static flags = {
16-
// flag with a value (-p, --path=VALUE)
17-
path: Flags.string({ char: 'p', description: 'path to project' }),
18-
}
19-
2015
async init(): Promise<void> {
2116
console.log('Running Codify plan...')
2217
return super.init();

src/common/base-command.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import { Command, Flags } from '@oclif/core';
2+
import { OutputFlags } from '@oclif/core/interfaces';
23
import chalk from 'chalk';
34
import { SudoRequestData } from 'codify-schemas';
45
import createDebug from 'debug';
56

67
import { Event, ctx } from '../events/context.js';
78
import { Reporter, ReporterFactory, ReporterType } from '../ui/reporters/reporter.js';
89
import { prettyPrintError } from './errors.js';
9-
import { OutputFlags } from '@oclif/core/interfaces';
1010

1111
export abstract class BaseCommand extends Command {
12-
1312
static enableJsonFlag = true;
13+
1414
static baseFlags = {
1515
'debug': Flags.boolean(),
1616
'output': Flags.option({
@@ -21,7 +21,8 @@ export abstract class BaseCommand extends Command {
2121
'secure': Flags.boolean({
2222
char: 's',
2323
default: false,
24-
})
24+
}),
25+
path: Flags.string({ char: 'p', description: 'Path to codify.json file' }),
2526
}
2627

2728
protected reporter!: Reporter;

src/plugins/plugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export class Plugin implements IPlugin {
6868
const result = await this.process!.sendMessageForResult('validate', { configs: jsonConfigs });
6969

7070
if (!result.isSuccessful()) {
71-
throw new Error(`Initialize error for plugin: "${this.name}" \n\n` + result.data);
71+
throw new Error(`Validate error for plugin: "${this.name}" \n\n${JSON.stringify(result.data, null, 2)}`);
7272
}
7373

7474
if (!this.validateValidateResponse(result.data)) {

src/plugins/resolver.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,18 +84,18 @@ export class PluginResolver {
8484
}
8585

8686
// Plugin already exists, then no need to download. OR couldn't fetch plugin info from online then just resolve local version. OR we already have the latest version
87-
if ((version !== 'latest' && localPluginExists)
88-
|| (localPluginExists && !latestInfoFromNetwork)
89-
|| (resolvedVersion === latestInfoFromNetwork!.version)
87+
if (resolvedVersion &&
88+
((localPluginExists && !latestInfoFromNetwork)
89+
|| (resolvedVersion === latestInfoFromNetwork!.version))
9090
) {
91-
return PluginResolver.resolveLocalPlugin(name, `${PLUGIN_CACHE_DIR}/${name}/${version}/index.js`);
91+
return PluginResolver.resolveLocalPlugin(name, `${PLUGIN_CACHE_DIR}/${name}/${resolvedVersion}/index.js`);
9292
}
9393

9494
return downloadFreshPlugin();
9595

9696
// Set up folders and download plugin from the network.
9797
async function downloadFreshPlugin(): Promise<Plugin> {
98-
const filePath = `${PLUGIN_CACHE_DIR}/${name}/${version}/index.js`;
98+
const filePath = `${PLUGIN_CACHE_DIR}/${name}/${latestInfoFromNetwork?.version}/index.js`;
9999
await ApiClient.downloadPlugin(filePath, latestInfoFromNetwork!.downloadLink);
100100

101101
return new Plugin(

test/integration/resolver.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,19 @@ describe('Plugin resolver integration test', () => {
2020
it('resolves the default plugin', async () => {
2121
await PluginResolver.resolveAll({ 'default': 'latest' })
2222
expect(fs.existsSync(path.resolve(os.homedir(), '.codify/plugins/default'))).to.be.true;
23+
24+
const files = fs.readdirSync(path.resolve(os.homedir(), '.codify/plugins/default'));
25+
expect(files.length).to.eq(1);
26+
27+
// The folder names are semver versions for the plugins (ex. 0.11.0, 0.12, etc)
28+
const semverRegex = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/
29+
expect(semverRegex.test(files[0])).to.be.true;
30+
31+
const pluginPath = path.resolve(os.homedir(), '.codify/plugins/default', files[0])
32+
const pluginFolder = fs.readdirSync(pluginPath)
33+
34+
expect(pluginFolder.length).to.eq(1);
35+
expect(pluginFolder[0]).to.eq('index.js')
2336
})
2437

2538
afterEach(() => {

0 commit comments

Comments
 (0)