Skip to content
Merged
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
5 changes: 5 additions & 0 deletions .changeset/thin-beds-sniff.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@aiou/neo": patch
---

pref should be original user-input
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
"terminal-link": "^3.0.0",
"typescript": "^5.6.3",
"vitest": "^0.7.7",
"vitest-extra": "^0.0.4",
"vitest-extra": "^0.1.0",
"write-yaml-file": "^5.0.0",
"zen-observable": "^0.8.15"
}
Expand Down
9 changes: 4 additions & 5 deletions packages/core/src/commands/run.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import path from 'node:path'

import parseWantedDependency from '@pnpm/parse-wanted-dependency'
import fs from 'fs-extra'
import Listr from 'listr'

Expand All @@ -9,7 +8,7 @@ import { isYaml } from '../utils'
import { debug } from '../utils/logger'
import { runMario } from '../utils/mario'
import { usage } from '../utils/show-usage'

import { parseWantedPackage } from '../utils/find-pref-package'
import type { CommonOptions } from '../interface'

export type RunOptions = CommonOptions & { module?: string[] }
Expand All @@ -33,9 +32,9 @@ export const run = async (alias: string, params: RunOptions) => {
{
title: `Download mario generator ${alias}`,
task: async () => {
const result = parseWantedDependency(alias)
const response = await store.pm.request({ alias: result.alias, pref: result.pref })
await store.pm.import(target, response)
const result = parseWantedPackage(alias)
const response = await store.pm.request({ alias: result.alias, pref: result.pref, latest: result.version === 'latest' })
await store.pm.import(target, response, { latest: result.version === 'latest' })
return true
},
},
Expand Down
13 changes: 13 additions & 0 deletions packages/core/src/interface/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ export interface Package extends PresetTemplate {
version: string
pref: string
id: string
// will be selected in create command(inquirer.search-list), if duplicated in lockfile
// name will be uniq by Lockfile, create uniq name by makeUniqId, format: <original-name>(<pref>)
// however, package store in .neo-lock.yaml can be duplicated
name: string
cached?: boolean
// package from which preset
preset?: string
Expand All @@ -27,8 +31,17 @@ export interface Package extends PresetTemplate {
}

export interface LockFile {
// neo version
version?: string
/**
* @description cached templates
* 1. once cmd-add with type=template, the template will be cached
* 2. once cmd-create from store(preset), the template will be cached
*/
templates?: Record<string, Package>
/**
* @description presets
*/
presets?: Record<string, Preset>
}

Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,10 @@ const createStore = async (params: CommonOptions) => {
return
}
const { id } = response.body
// templates pkgs maybe has same name, use id as key
// name and pref parsed from user-input
await lockFile.updateTemplates({
[params.name]: {
[id]: {
name: params.name,
version: response.body.manifest?.version,
id,
Expand Down
7 changes: 5 additions & 2 deletions packages/core/src/utils/find-pref-package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,19 @@ import { randomUUID } from 'node:crypto'
import parseWantedDependency from '@pnpm/parse-wanted-dependency'

import type { Package } from '../interface'
import { debug } from './logger'

export const parseWantedPackage = (input: string) => {
const { alias, pref } = parseWantedDependency(input)
return {
const options = {
_name: alias || input,
name: alias || input,
alias,
version: pref,
pref: alias || input,
pref: input,
}
debug.utils('parse input %s into %O', input, options)
return options
}

/**
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/utils/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export const debug = {
list: Debug('neo:cmd:list'),
run: Debug('neo:cmd:run'),
cleanup: Debug('neo:cmd:cleanup'),
utils: Debug('neo:utils'),
}

export default {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/test/__snapshots__/store.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ exports[`store > add preset 1`] = `
exports[`store > add template 1`] = `
{
"templates": {
"bin": {
"@aiou/bin-template/4.0.0": {
"id": "@aiou/bin-template/4.0.0",
"name": "bin",
"pref": "@aiou/bin-template",
Expand Down Expand Up @@ -179,7 +179,7 @@ exports[`store > add(type=preset) 1`] = `
exports[`store > add(type=template) 1`] = `
{
"templates": {
"@aiou/bin-template": {
"@aiou/bin-template/3.0.1": {
"id": "@aiou/bin-template/3.0.1",
"name": "@aiou/bin-template",
"pref": "@aiou/bin-template@3.0.1",
Expand Down
15 changes: 15 additions & 0 deletions packages/core/test/cmd-add/__snapshots__/tpl-github.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Vitest Snapshot v1

exports[`load template from github should work 1`] = `
{
"templates": {
"@aiou/actions-template/0.3.0": {
"id": "@aiou/actions-template/0.3.0",
"name": "https://github.com/neo-hack/actions-template",
"pref": "https://github.com/neo-hack/actions-template",
"version": "0.3.0",
},
},
"version": undefined,
}
`;
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
exports[`load template from npm should work 1`] = `
{
"templates": {
"@aiou/ts-lib-template": {
"@aiou/ts-lib-template/0.6.0": {
"id": "@aiou/ts-lib-template/0.6.0",
"name": "@aiou/ts-lib-template",
"pref": "@aiou/ts-lib-template",
Expand Down
25 changes: 19 additions & 6 deletions packages/core/test/cmd-add/tpl-github.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
import { clearLockFile } from '../helpers'
import {
clearLockFile,
execNeo,
randomStoreDir,
readLockFile,
} from '../helpers'

afterEach(() => {
clearLockFile()
})

it.todo('fix timeout, load template from github should work')

// it('load template from github should work', async () => {
// const url = 'https://github.com/neo-hack/actions-template'
// await execNeo(['add', url, '--store-dir', storeDir])
// expect(readLockFile()).toMatchSnapshot()
// })
const storeDir: string = randomStoreDir()

it('load template from github should work', async () => {
const url = 'https://github.com/neo-hack/actions-template'
await execNeo(['add', url, '--store-dir', storeDir], {
env: {
DEBUG: 'neo:*',
},
stderr: 'inherit',
stdout: 'inherit',
})
expect(await readLockFile(storeDir)).toMatchSnapshot()
})
7 changes: 5 additions & 2 deletions packages/core/test/cmd-run/run.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,13 @@ describe('command run', () => {
)
})

it('run ci part should work', async () => {
it('run ci part should work #debug', async () => {
fs.removeSync(r('test/fixtures/prepack-ci/output/.github'))
await execNeo(['run', '@aiou/generator-pnpm-ci', '--module', 'workflows'], {
await execNeo(['run', '@aiou/generator-pnpm-ci', '--module', 'workflows', '--store-dir', storeDir], {
cwd: path.resolve(r('test/fixtures/prepack-ci/output')),
env: {
DEBUG: 'neo:*',
},
})
expect(r('test/fixtures/prepack-ci/output')).toMatchDir(r('test/fixtures/prepack-ci/expected'))
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ jobs:

strategy:
matrix:
node-version: [16.x, 18.x]
node-version: [20.x, 22.x]

steps:
- name: Checkout code repository
uses: actions/checkout@v4
uses: actions/checkout@v5
with:
fetch-depth: 0
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
# Install pnpm depends on package.json packageManager field
- uses: pnpm/action-setup@v2
- uses: pnpm/action-setup@v4
name: Install pnpm
id: pnpm-install
with:
Expand All @@ -33,7 +33,7 @@ jobs:
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- uses: actions/cache@v3
- uses: actions/cache@v4
name: Setup pnpm cache
with:
path: ${{ env.STORE_PATH }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ jobs:
pull-requests: write
steps:
- name: Checkout code repository
uses: actions/checkout@v4
uses: actions/checkout@v5
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 18
node-version: 20
# Install pnpm depends on package.json packageManager field
- uses: pnpm/action-setup@v2
- uses: pnpm/action-setup@v4
name: Install pnpm
id: pnpm-install
with:
Expand All @@ -34,7 +34,7 @@ jobs:
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- uses: actions/cache@v3
- uses: actions/cache@v4
name: Setup pnpm cache
with:
path: ${{ env.STORE_PATH }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: checkout code repository
uses: actions/checkout@v4
uses: actions/checkout@v5
with:
fetch-depth: 0
- name: setup node.js
uses: actions/setup-node@v4
with:
node-version: 18
- uses: pnpm/action-setup@v2
node-version: 20
- uses: pnpm/action-setup@v4
name: Install pnpm
id: pnpm-install
with:
Expand All @@ -35,7 +35,7 @@ jobs:
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_ENV
- uses: actions/cache@v3
- uses: actions/cache@v4
name: setup pnpm cache
with:
path: ${{ env.STORE_PATH }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ jobs:

strategy:
matrix:
node-version: [16.x, 18.x]
node-version: [20.x, 22.x]

steps:
- name: Checkout code repository
uses: actions/checkout@v4
uses: actions/checkout@v5
with:
fetch-depth: 0
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
# Install pnpm depends on package.json packageManager field
- uses: pnpm/action-setup@v2
- uses: pnpm/action-setup@v4
name: Install pnpm
id: pnpm-install
with:
Expand All @@ -33,7 +33,7 @@ jobs:
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- uses: actions/cache@v3
- uses: actions/cache@v4
name: Setup pnpm cache
with:
path: ${{ env.STORE_PATH }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ jobs:
pull-requests: write
steps:
- name: Checkout code repository
uses: actions/checkout@v4
uses: actions/checkout@v5
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 18
node-version: 20
# Install pnpm depends on package.json packageManager field
- uses: pnpm/action-setup@v2
- uses: pnpm/action-setup@v4
name: Install pnpm
id: pnpm-install
with:
Expand All @@ -34,7 +34,7 @@ jobs:
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- uses: actions/cache@v3
- uses: actions/cache@v4
name: Setup pnpm cache
with:
path: ${{ env.STORE_PATH }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: checkout code repository
uses: actions/checkout@v4
uses: actions/checkout@v5
with:
fetch-depth: 0
- name: setup node.js
uses: actions/setup-node@v4
with:
node-version: 18
- uses: pnpm/action-setup@v2
node-version: 20
- uses: pnpm/action-setup@v4
name: Install pnpm
id: pnpm-install
with:
Expand All @@ -35,7 +35,7 @@ jobs:
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_ENV
- uses: actions/cache@v3
- uses: actions/cache@v4
name: setup pnpm cache
with:
path: ${{ env.STORE_PATH }}
Expand Down
3 changes: 3 additions & 0 deletions packages/core/test/fixtures/prepack/expected/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": ["@aiou"]
}
Loading