Skip to content
This repository has been archived by the owner on Jul 5, 2024. It is now read-only.

Commit

Permalink
feat: check syntax in ci
Browse files Browse the repository at this point in the history
  • Loading branch information
bvanjoi committed Dec 25, 2023
1 parent ee0be90 commit 9a1c815
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 41 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,7 @@ jobs:
cache: 'pnpm'
- name: Install Dependencies
run: pnpm install
- name: Check
run: npm run check
- name: Build
run: npm run build
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"name": "rspack-compat",
"private": true,
"scripts": {
"build": "pnpm --filter './packages/**' build"
"build": "pnpm --filter './packages/**' build",
"check": "node ./scripts/check.js"
},
"packageManager": "pnpm@8.9.0"
}
8 changes: 8 additions & 0 deletions scripts/check.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const { readCompat, PACKAGE_DIR } = require("./utils");

async function runCheck() {
await readCompat(PACKAGE_DIR)
console.log('=== check syntax success')
}

runCheck();
44 changes: 4 additions & 40 deletions scripts/upload.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const path = require('path');
const fs = require('fs/promises');
const fsSync = require('fs');
const assert = require('assert');
const { spawn } = require('child_process')
const { spawn } = require('child_process');
const { PACKAGE_DIR, ROOT_DIR, readCompat } = require('./utils');

async function runCommand(
command,
Expand Down Expand Up @@ -30,51 +30,15 @@ async function runCommand(
throw new Error(`${command} ${args.join(" ")} failed with ${exitCode}`);
}

function ok(value) {
assert(value)
}


const root = path.resolve(__dirname, '..');
const dataDir = path.resolve(root, '.data');

/**
* @param {string} name
* @returns {[string, string]}
*/
function splitPackageName(name) {
return name.split('@')
}

/**
* @param {string} dir
*/
async function readCompat(dir) {
const list = await fs.readdir(dir);
return list.map(item => {
const [name, version] = splitPackageName(item);
const abs = path.resolve(dir, item, 'package.json');
const info = require(abs).rspack;
ok(typeof info.version === 'string')
ok(typeof name === 'string')
ok(typeof version === 'string')
return {
name,
version,
rspackVersion: info.version,
path: path.relative(root, path.resolve(dir, item))
}
})
}

/**
* @param {string[]} args
*/
async function run(args) {
const dir = path.resolve(root, 'packages');
const jsonStr = await readCompat(dir).then((list) => JSON.stringify(list, undefined, 2));
const jsonStr = await readCompat(PACKAGE_DIR).then((list) => JSON.stringify(list, undefined, 2));
const name = 'rspack-compat.json'
const abs = path.resolve(root, name)
const abs = path.resolve(ROOT_DIR, name)
// write file to root
await fs.writeFile(abs, jsonStr)

Expand Down
41 changes: 41 additions & 0 deletions scripts/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
const assert = require('assert');
const path = require('path');
const fs = require('fs/promises');

/**
* @param {string} name
* @returns {[string, string]}
*/
function splitPackageName(name) {
return name.split('@')
}

/**
* @param {string} dir
*/
async function readCompat(dir) {
const list = await fs.readdir(dir);
return list.map(item => {
const [name, version] = splitPackageName(item);
const abs = path.resolve(dir, item, 'package.json');
const info = require(abs).rspack;
assert(typeof name === 'string', 'Please add the name for the supported plugin')
assert(typeof version === 'string', `Please add the support version of \`${item}\``)
assert(typeof info.version === 'string', 'Please add the minimal version of rspack supported in package.json')
return {
name,
version,
rspackVersion: info.version,
path: path.relative(ROOT_DIR, path.resolve(dir, item))
}
})
}

const ROOT_DIR = path.resolve(__dirname, '..')
const PACKAGE_DIR = path.resolve(ROOT_DIR, 'packages');

module.exports = {
readCompat,
ROOT_DIR,
PACKAGE_DIR
}

0 comments on commit 9a1c815

Please sign in to comment.