From add4b4864c3d925b6cdbab1b05143ca55cfae85b Mon Sep 17 00:00:00 2001 From: Edwin Kofler Date: Sun, 26 May 2024 21:36:44 -0700 Subject: [PATCH] Move `package.json` to parent directory (#3801) --- src/.c8rc.json => .c8rc.json | 0 src/.eslintrc.json => .eslintrc.json | 0 .github/PULL_REQUEST_TEMPLATE.md | 1 - .github/workflows/nodejs.yml | 6 ++--- .gitignore | 15 ++----------- .pre-commit-config.yaml | 4 ++-- .prettierrc.cjs | 22 +++---------------- CONTRIBUTING.md | 5 ++--- src/Gruntfile.cjs => Gruntfile.cjs | 15 +++++++------ src/package-lock.json => package-lock.json | 0 src/package.json => package.json | 5 ++--- {src/scripts => scripts}/coverage.sh | 0 .../dirty_repository_check.sh | 0 src/scripts/pre-commit-script.sh | 17 -------------- 14 files changed, 21 insertions(+), 69 deletions(-) rename src/.c8rc.json => .c8rc.json (100%) rename src/.eslintrc.json => .eslintrc.json (100%) rename src/Gruntfile.cjs => Gruntfile.cjs (99%) rename src/package-lock.json => package-lock.json (100%) rename src/package.json => package.json (86%) rename {src/scripts => scripts}/coverage.sh (100%) rename {src/scripts => scripts}/dirty_repository_check.sh (100%) delete mode 100755 src/scripts/pre-commit-script.sh diff --git a/src/.c8rc.json b/.c8rc.json similarity index 100% rename from src/.c8rc.json rename to .c8rc.json diff --git a/src/.eslintrc.json b/.eslintrc.json similarity index 100% rename from src/.eslintrc.json rename to .eslintrc.json diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index dcfce64d74a..961a0e633c7 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -8,5 +8,4 @@ Adding a JSON schema file to the catalog is required. Add tests files. (.json, .yml, .yaml or .toml) Use the most recent JSON Schema version that's well supported by editors and IDEs, currently draft-07. JSON formatted according to the .editorconfig settings. - --> diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index 8a5fcb6cf6f..f6113a633f2 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -11,14 +11,12 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: - cache: 'npm' node-version: '18' - cache-dependency-path: src/package-lock.json + cache: 'npm' + cache-dependency-path: './package-lock.json' - name: npm ci run: | - cd src npm ci - name: npm run build run: | - cd src npm run build diff --git a/.gitignore b/.gitignore index 493e4654585..798a7ae40cd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,13 +1,8 @@ -################# -## Prettier -################# # This ignore file is shared with Prettier. It seems .git/ must be ignored manually now. .git/ -################# -## Visual Studio -################# - +# Project files +temp test.json *.webinfo .vs/ @@ -26,7 +21,6 @@ test.json node_modules/ # Build results - packages/ [Oo]bj/ @@ -109,10 +103,6 @@ publish/ *.Publish.xml *.pubxml -# NuGet Packages Directory -## TODO: If you have NuGet Package Restore enabled, uncomment the next line -#packages/ - # Windows Azure Build Output csx *.build.csdef @@ -132,7 +122,6 @@ ClientBin/ *.pfx *.publishsettings .DS_Store -src/temp # RIA/Silverlight projects Generated_Code/ diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 7eb4f103b80..243838bbc35 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -10,12 +10,12 @@ repos: - 'prettier@3.2.5' - 'prettier-plugin-sort-json@4.0.0' pass_filenames: true - entry: './src/scripts/pre-commit-script.sh' + args: ['--no-color', '--log-level=warn', '--write'] - repo: 'https://github.com/codespell-project/codespell' rev: 'v2.2.6' hooks: - id: 'codespell' - exclude: '^src/(package-lock.json|test/openutau-ustx/bulaomeng.ustx.yaml|test/kustomization/labels.json|bin/.*)$' + exclude: '^(package-lock.json|src/test/openutau-ustx/bulaomeng.ustx.yaml|src/test/kustomization/labels.json|src/bin/.*)$' args: [ '-Lcrate,ninjs,ans,specif,seh,specifid,deriver,isnt,tye,forin,dependees,rouge,interm,fo,wast,nome,statics,ue,aack,gost,inout,provId,handels,bu,testng,ags,edn,aks,te,decorder,provid,branche,alse,nd,mape,wil,clude,wit,flate,omlet', diff --git a/.prettierrc.cjs b/.prettierrc.cjs index 8715dfaf08b..7e26b19f100 100644 --- a/.prettierrc.cjs +++ b/.prettierrc.cjs @@ -1,23 +1,7 @@ -/** @type {unknown} */ -let prettierPluginSortJson -try { - // When running scripts locally (through npm-run-script), the relative path of the plugin - // must be specified since 'require.resolve' will not find it by itself in subdirectory 'src'. - prettierPluginSortJson = require.resolve( - './src/node_modules/prettier-plugin-sort-json', - ) -} catch (err) { - // In pre-commit CI, 'prettier-plugin-sort-json' is installed to some directory (which is in $NODE_PATH). - // As as result, simply require.resolve to find the full path to the dependency. - prettierPluginSortJson = require.resolve('prettier-plugin-sort-json') -} -if (!prettierPluginSortJson) { - throw new Error(`Failed to import plugin: 'prettier-plugin-sort-json'`) -} - -/** @type {import('./src/node_modules/prettier').Config} */ +/** @type {import('prettier').Config} */ module.exports = { - plugins: [prettierPluginSortJson], + // pre-commit.ci fails without `require.resolve()`. + plugins: [require.resolve('prettier-plugin-sort-json')], semi: false, singleQuote: true, trailingComma: 'all', diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d19e532b1b8..50f08934141 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -198,10 +198,9 @@ git clone https://github.com/SchemaStore/schemastore cd schemastore ``` -Be sure that [NodeJS](https://nodejs.org) is installed. The minimum required NodeJS version is defined by the `engines` key in [package.json](src/package.json). Now, install dependencies and run the `new_schema` Grunt task: +Be sure that [NodeJS](https://nodejs.org) is installed. The minimum required NodeJS version is defined by the `engines` key in [package.json](package.json). Now, install dependencies and run the `new_schema` Grunt task: ```sh -cd src npm install npm run grunt new_schema ``` @@ -280,7 +279,7 @@ git clone https://github.com/SchemaStore/schemastore cd schemastore ``` -Be sure that [NodeJS](https://nodejs.org) is installed. The minimum required NodeJS version is defined by the `engines` key in [package.json](src/package.json). +Be sure that [NodeJS](https://nodejs.org) is installed. The minimum required NodeJS version is defined by the `engines` key in [package.json](package.json). Now, modify the schema you intend to modify. Schemas are located under `src/schemas/json`. diff --git a/src/Gruntfile.cjs b/Gruntfile.cjs similarity index 99% rename from src/Gruntfile.cjs rename to Gruntfile.cjs index 5d24d35bae9..ea7cb2dcca8 100644 --- a/src/Gruntfile.cjs +++ b/Gruntfile.cjs @@ -18,14 +18,14 @@ const axios = require('axios').default const jsonlint = require('@prantlf/jsonlint') const jsoncParser = require('jsonc-parser') -const temporaryCoverageDir = 'temp' -const schemaDir = 'schemas/json' -const testPositiveDir = 'test' -const testNegativeDir = 'negative_test' +const temporaryCoverageDir = './temp' +const schemaDir = './src/schemas/json' +const testPositiveDir = './src/test' +const testNegativeDir = './src/negative_test' const urlSchemaStore = 'https://json.schemastore.org/' -const catalog = require('./api/json/catalog.json') +const catalog = require('./src/api/json/catalog.json') const schemaValidation = jsoncParser.parse( - fs.readFileSync('./schema-validation.json', 'utf-8'), + fs.readFileSync('./src/schema-validation.json', 'utf-8'), ) const schemasToBeTested = fs.readdirSync(schemaDir) const foldersPositiveTest = fs.readdirSync(testPositiveDir) @@ -966,7 +966,7 @@ module.exports = function (/** @type {import('grunt')} */ grunt) { 'local_assert_catalog.json_passes_jsonlint', 'Check that catalog.json passes jsonlint', function () { - jsonlint.parse(fs.readFileSync('./api/json/catalog.json', 'utf-8'), { + jsonlint.parse(fs.readFileSync('./src/api/json/catalog.json', 'utf-8'), { ignoreBOM: false, ignoreComments: false, ignoreTrailingCommas: false, @@ -1973,6 +1973,7 @@ module.exports = function (/** @type {import('grunt')} */ grunt) { } // Prettify the JavaScript module code + // TODO: https://github.com/prettier/prettier/pull/12788 const prettierOptions = prettier.resolveConfig.sync(process.cwd()) fs.writeFileSync( javaScriptCoverageNameWithPath, diff --git a/src/package-lock.json b/package-lock.json similarity index 100% rename from src/package-lock.json rename to package-lock.json diff --git a/src/package.json b/package.json similarity index 86% rename from src/package.json rename to package.json index 7183940e2cb..b044c986de5 100644 --- a/src/package.json +++ b/package.json @@ -2,7 +2,6 @@ "name": "schemastore.org", "version": "1.0.0", "description": "A collection of JSON Schemas", - "readme": "../README.md", "private": true, "homepage": "https://schemastore.org", "bugs": { @@ -19,8 +18,8 @@ "type": "commonjs", "scripts": { "grunt": "grunt", - "prettier": "prettier --config ../.prettierrc.cjs --ignore-path ../.gitignore --check ..", - "prettier:fix": "prettier --config ../.prettierrc.cjs --ignore-path ../.gitignore --write ..", + "prettier": "prettier --config .prettierrc.cjs --ignore-path .gitignore --check .", + "prettier:fix": "prettier --config .prettierrc.cjs --ignore-path .gitignore --write .", "eslint": "eslint Gruntfile.cjs", "eslint:fix": "eslint --fix Gruntfile.cjs", "build": "npm run eslint && grunt && ./scripts/dirty_repository_check.sh", diff --git a/src/scripts/coverage.sh b/scripts/coverage.sh similarity index 100% rename from src/scripts/coverage.sh rename to scripts/coverage.sh diff --git a/src/scripts/dirty_repository_check.sh b/scripts/dirty_repository_check.sh similarity index 100% rename from src/scripts/dirty_repository_check.sh rename to scripts/dirty_repository_check.sh diff --git a/src/scripts/pre-commit-script.sh b/src/scripts/pre-commit-script.sh deleted file mode 100755 index b88d2e1f453..00000000000 --- a/src/scripts/pre-commit-script.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env bash -set -e - -# Because pre-commit is unable to run hooks in a subdirectory (see -# https://github.com/pre-commit/pre-commit/issues/1417), we must do it -# ourselves by cd'ing to the directory and modifying the list of staged -# files ourselves (which defeats the point of pre-commit's plugin system). - -if (($# == 0)); then - # There are no staged files - there is nothing to do here. - exit 0 -fi - -cd src -set -- "${@/#/../}" # Prepends '../' to each staged file -echo VV "$@" VV -prettier --no-color --log-level=warn --write "$@"