From 40f8d1d63bd54f6d68fb28d6a72f3be238799215 Mon Sep 17 00:00:00 2001 From: Gerkin Date: Sun, 26 Jun 2022 14:52:38 +0200 Subject: [PATCH] fix: continue fixes for Windows scripts --- package-lock.json | 28 ++++++++++++++++++++++++++++ package.json | 13 +++++++------ tools/package-proto.js | 22 +++++++++++++--------- 3 files changed, 48 insertions(+), 15 deletions(-) diff --git a/package-lock.json b/package-lock.json index 956d112d..cb329a35 100644 --- a/package-lock.json +++ b/package-lock.json @@ -20,6 +20,7 @@ "@typescript-eslint/parser": "^5.28.0", "chalk": "^4.1.2", "concurrently": "^7.2.2", + "cross-env": "^7.0.3", "eslint": "^8.18.0", "eslint-plugin-eslint-comments": "^3.2.0", "eslint-plugin-import": "^2.26.0", @@ -3116,6 +3117,24 @@ "integrity": "sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==", "dev": true }, + "node_modules/cross-env": { + "version": "7.0.3", + "resolved": "https://registry.npmjs.org/cross-env/-/cross-env-7.0.3.tgz", + "integrity": "sha512-+/HKd6EgcQCJGh2PSjZuUitQBQynKor4wrFbRg4DtAgS1aWO+gU52xpH7M9ScGgXSYmAVS9bIJ8EzuaGw0oNAw==", + "dev": true, + "dependencies": { + "cross-spawn": "^7.0.1" + }, + "bin": { + "cross-env": "src/bin/cross-env.js", + "cross-env-shell": "src/bin/cross-env-shell.js" + }, + "engines": { + "node": ">=10.14", + "npm": ">=6", + "yarn": ">=1" + } + }, "node_modules/cross-spawn": { "version": "7.0.3", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", @@ -11955,6 +11974,15 @@ "integrity": "sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==", "dev": true }, + "cross-env": { + "version": "7.0.3", + "resolved": "https://registry.npmjs.org/cross-env/-/cross-env-7.0.3.tgz", + "integrity": "sha512-+/HKd6EgcQCJGh2PSjZuUitQBQynKor4wrFbRg4DtAgS1aWO+gU52xpH7M9ScGgXSYmAVS9bIJ8EzuaGw0oNAw==", + "dev": true, + "requires": { + "cross-spawn": "^7.0.1" + } + }, "cross-spawn": { "version": "7.0.3", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", diff --git a/package.json b/package.json index 9b199e39..2cfaf4ce 100644 --- a/package.json +++ b/package.json @@ -31,21 +31,21 @@ "precommit": "npm run projects:patch -- diff && npm run lint -- --cache && npm run projects:build && npm run projects:test -- --onlyChanged && npm run docs", "prepare": "npm run prepare:husky", "prepare:husky": "run-script-os", - "prepare:husky:windows": " if exist './node_modules/husky' { husky install }", "prepare:husky:default": "[ -d ./node_modules/husky ] && husky install || true", + "prepare:husky:windows": "if exist './node_modules/husky' { husky install }", "projects:build": "npm run projects:patch -- apply && node ./tools/s-projects \"npm run build -- --pretty\"", "projects:build:clean": "npm run build:clean --workspaces", "projects:build:watch": "npm run projects:build && node ./tools/p-projects \"npm run build -- --watch --preserveWatchOutput --pretty\"", "projects:patch": "node ./tools/typedoc-patcher --no-stash", "projects:test": "jest", "release": "run-script-os", - "release:windows": "echo \"Unsupported platform for release. Run this command only from an UNIX-like environment.\"", "release:default": "./tools/release.sh", - "test:ci": "JEST_JUNIT_OUTPUT_NAME=junit.xml jest --config jest.config.ci.js --all --ci --reporters=default --reporters=jest-junit", + "release:windows": "echo \"Unsupported platform for release. Run this command only from an UNIX-like environment.\"", + "test:ci": "cross-env JEST_JUNIT_OUTPUT_NAME=junit.xml jest --config jest.config.ci.js --all --ci --reporters=default --reporters=jest-junit", "test:ci:coverage": "npm run test:ci -- --collectCoverage", - "tools:bump-versions": "NODE_NO_WARNINGS=1 node tools/bump-versions", - "tools:infer-next-version": "NODE_NO_WARNINGS=1 node tools/infer-next-version", - "tools:packages-sync": "NODE_NO_WARNINGS=1 node tools/package-proto" + "tools:bump-versions": "cross-env NODE_NO_WARNINGS=1 node tools/bump-versions", + "tools:infer-next-version": "cross-env NODE_NO_WARNINGS=1 node tools/infer-next-version", + "tools:packages-sync": "cross-env NODE_NO_WARNINGS=1 node tools/package-proto" }, "commitlint": { "extends": [ @@ -61,6 +61,7 @@ "@typescript-eslint/parser": "^5.28.0", "chalk": "^4.1.2", "concurrently": "^7.2.2", + "cross-env": "^7.0.3", "eslint": "^8.18.0", "eslint-plugin-eslint-comments": "^3.2.0", "eslint-plugin-import": "^2.26.0", diff --git a/tools/package-proto.js b/tools/package-proto.js index 9a7994df..a4767e35 100644 --- a/tools/package-proto.js +++ b/tools/package-proto.js @@ -1,13 +1,15 @@ const assert = require( 'assert' ); const { createHash } = require( 'crypto' ); const { readFile, writeFile, mkdir, copyFile, access, unlink } = require( 'fs/promises' ); -const { resolve, join } = require( 'path' ); +const { EOL } = require( 'os' ); +const { resolve, join, normalize } = require( 'path' ); const { bold, yellow } = require( 'chalk' ); const { defaultsDeep, partition, memoize, isString, cloneDeep, uniq } = require( 'lodash' ); const { spawn, globAsync, selectProjects, createStash } = require( './utils' ); +const normalizePath = path => normalize( path ).replace( /\\/g, '/' ); const getDocsUrl = pkgJson => `https://knodescommunity.github.io/typedoc-plugins/modules/${( pkgJson.name ?? assert.fail( 'No name' ) ).replace( /[^a-z0-9]/gi, '_' )}.html`; /** * @typedef {import('./utils').Project} Project @@ -69,14 +71,16 @@ const packageJson = () => { await writeFile( packagePath, JSON.stringify( newProjectPkg, null, 2 ) ); }, tearDown: async( proto, projects ) => { - await spawn( 'npx', [ 'format-package', '--write', ...projects.map( p => resolve( p.path, 'package.json' ) ) ] ); + await spawn( + process.platform === 'win32' ? '.\\node_modules\\.bin\\format-package.cmd' : './node_modules/.bin/format-package', + [ '--write', ...projects.map( p => normalizePath( resolve( p.path, 'package.json' ) ) ) ] ); }, handleFile: filename => /(\/|^)package\.json$/.test( filename ), }; }; const checksum = async file => createHash( 'md5' ) - .update( await readFile( file, 'utf-8' ), 'utf-8' ) + .update( ( await readFile( file, 'utf-8' ) ).replace( /\r?\n/g, '\n' ), 'utf-8' ) .digest( 'hex' ); /** @@ -88,7 +92,7 @@ const syncFs = () => { try { const cacheContent = ( await tryReadFile( cacheFile, 'utf-8' ) ) ?? ''; return cacheContent - .split( '\n' ) + .split( /\r?\n/ ) .filter( v => v.trim() ) .reduce( ( acc, line ) => { const parts = line.split( '::' ).map( p => p.trim() ); @@ -209,10 +213,10 @@ const readme = () => { } let newHeader = `# ${packageContent.name}`; if( packageContent.description ){ - newHeader += `\n\n> ${packageContent.description}`; + newHeader += `${EOL}${EOL}> ${packageContent.description}`; } const shield = ( label, suffix, link ) => `[![${label}](https://img.shields.io${suffix}?style=for-the-badge)](${link})`; - newHeader += `\n + newHeader += `${EOL} ${shield( 'npm version', `/npm/v/${packageContent.name}`, `https://www.npmjs.com/package/${packageContent.name}` )} ${shield( 'npm downloads', `/npm/dm/${packageContent.name}`, `https://www.npmjs.com/package/${packageContent.name}` )} [![Compatible with TypeDoc](https://img.shields.io/badge/For%20typedoc-${packageContent.peerDependencies.typedoc}-green?logo=npm&style=for-the-badge)](https://www.npmjs.com/package/typedoc) @@ -252,11 +256,11 @@ For more infos, please refer to [the documentation](${getDocsUrl( packageContent ${newHeader} `; - const headerRegex = /^(.*?)\n/s; + const headerRegex = /^(.*?)\r?\n/s; if( !headerRegex.test( readmeContent ) ){ console.log( yellow( `Header not found in ${readmeFile}` ) ); } - const newReadme = newHeader + readmeContent.replace( /^(.*?)(\n|$)/s, '' ); + const newReadme = newHeader + readmeContent.replace( /^(.*?)(\r?\n|$)/s, '' ); await writeFile( readmeFile, newReadme ); }; return { @@ -283,7 +287,7 @@ if( require.main === module ){ } }, { explicitProjects: [], noStash: false } ); const projects = selectProjects( explicitProjects ); - const protoDir = resolve( __dirname, 'proto' ); + const protoDir = normalizePath( resolve( __dirname, 'proto' ) ); ( async () => { if( !noStash ){ await createStash( `Sync packages ${projects.map( p => p.name ).join( ' ' )}` );