From a109d05a7299d11339eba2d7742315b4c5cce683 Mon Sep 17 00:00:00 2001 From: Kamil Piechaczek Date: Thu, 29 Aug 2024 13:53:29 +0200 Subject: [PATCH 1/8] WIP. --- package.json | 6 +- .../utils/automated-tests/parsearguments.js | 20 +- .../utils/automated-tests/parsearguments.js | 67 +-- .../lib/builds/getdllpluginwebpackconfig.js | 3 +- packages/ckeditor5-dev-utils/lib/git.js | 185 ------- packages/ckeditor5-dev-utils/lib/index.js | 2 - packages/ckeditor5-dev-utils/lib/tools.js | 271 +---------- packages/ckeditor5-dev-utils/lib/workspace.js | 108 ----- .../tests/builds/getdllpluginwebpackconfig.js | 40 +- packages/ckeditor5-dev-utils/tests/git.js | 275 ----------- packages/ckeditor5-dev-utils/tests/tools.js | 453 +----------------- .../ckeditor5-dev-utils/tests/workspace.js | 171 ------- 12 files changed, 92 insertions(+), 1509 deletions(-) delete mode 100644 packages/ckeditor5-dev-utils/lib/git.js delete mode 100644 packages/ckeditor5-dev-utils/lib/workspace.js delete mode 100644 packages/ckeditor5-dev-utils/tests/git.js delete mode 100644 packages/ckeditor5-dev-utils/tests/workspace.js diff --git a/package.json b/package.json index 03741e5de..a9c519eda 100644 --- a/package.json +++ b/package.json @@ -1,10 +1,10 @@ { "name": "ckeditor5-dev", - "version": "42.1.0", + "version": "41.0.0", "private": true, "devDependencies": { - "@ckeditor/ckeditor5-dev-ci": "^42.1.0", - "@ckeditor/ckeditor5-dev-release-tools": "^42.1.0", + "@ckeditor/ckeditor5-dev-ci": "^41.0.0", + "@ckeditor/ckeditor5-dev-release-tools": "^41.0.0", "coveralls": "^3.1.1", "eslint": "^7.0.0", "eslint-config-ckeditor5": "^6.0.0", diff --git a/packages/ckeditor5-dev-tests/lib/utils/automated-tests/parsearguments.js b/packages/ckeditor5-dev-tests/lib/utils/automated-tests/parsearguments.js index 00715108b..eefdb774b 100644 --- a/packages/ckeditor5-dev-tests/lib/utils/automated-tests/parsearguments.js +++ b/packages/ckeditor5-dev-tests/lib/utils/automated-tests/parsearguments.js @@ -163,7 +163,7 @@ module.exports = function parseArguments( args ) { } const cwd = process.cwd(); - const shouldCheckExternalDirectory = tools.isDirectory( path.join( cwd, 'external' ) ); + const shouldCheckExternalDirectory = isDirectory( path.join( cwd, 'external' ) ); if ( !shouldCheckExternalDirectory ) { log.warning( 'The `external/` directory does not exist. Only the root repository will be checked.' ); @@ -172,8 +172,10 @@ module.exports = function parseArguments( args ) { const files = new Set( options.files ); for ( const repositoryName of options.repositories ) { + const cwdPackageJson = require( path.join( cwd, 'package.json' ) ); + // Check the main repository. - if ( repositoryName === tools.readPackageName( cwd ) ) { + if ( repositoryName === cwdPackageJson.name ) { addPackagesToCollection( files, path.join( cwd, 'packages' ) ); continue; @@ -187,7 +189,7 @@ module.exports = function parseArguments( args ) { const externalRepositoryPath = path.join( cwd, 'external', repositoryName ); // Check the "external" directory. - if ( tools.isDirectory( externalRepositoryPath ) ) { + if ( isDirectory( externalRepositoryPath ) ) { addPackagesToCollection( files, path.join( externalRepositoryPath, 'packages' ) ); } else { log.warning( `Did not find the repository "${ repositoryName }" in the root repository or the "external/" directory.` ); @@ -252,4 +254,16 @@ module.exports = function parseArguments( args ) { } ) .join( '' ); } + + /** + * @param {String} path + * @returns {Boolean} + */ + function isDirectory( path ) { + try { + return fs.statSync( path ).isDirectory(); + } catch ( e ) { + return false; + } + } }; diff --git a/packages/ckeditor5-dev-tests/tests/utils/automated-tests/parsearguments.js b/packages/ckeditor5-dev-tests/tests/utils/automated-tests/parsearguments.js index 166fbea2b..d76d9eb57 100644 --- a/packages/ckeditor5-dev-tests/tests/utils/automated-tests/parsearguments.js +++ b/packages/ckeditor5-dev-tests/tests/utils/automated-tests/parsearguments.js @@ -7,6 +7,7 @@ const fs = require( 'fs' ); const path = require( 'path' ); +const mockery = require( 'mockery' ); const { expect } = require( 'chai' ); const sinon = require( 'sinon' ); const proxyquire = require( 'proxyquire' ); @@ -14,38 +15,59 @@ const proxyquire = require( 'proxyquire' ); const originalPosixJoin = path.posix.join; describe( 'parseArguments()', () => { - let parseArguments, sandbox, stubs; + let parseArguments, sandbox, stubs, packageName; beforeEach( () => { sandbox = sinon.createSandbox(); + mockery.enable( { + useCleanCache: true, + warnOnReplace: false, + warnOnUnregistered: false + } ); + stubs = { cwd: sandbox.stub( process, 'cwd' ).callsFake( () => '/' ), existsSync: sandbox.stub( fs, 'existsSync' ), tools: { - isDirectory: sandbox.stub(), - readPackageName: sandbox.stub(), getDirectories: sandbox.stub() }, logger: { warning: sandbox.stub() }, + fs: { + statSync: sandbox.stub() + }, // To force unix paths in tests. pathJoin: sandbox.stub( path, 'join' ).callsFake( ( ...chunks ) => originalPosixJoin( ...chunks ) ) }; + stubs.cwd.returns( '/home/project' ); + + packageName = 'ckeditor5'; + + mockery.registerMock( '/home/project/package.json', { + get name() { + return packageName; + } + } ); + + // mockery.registerMock( 'fs', stubs.fs ); + parseArguments = proxyquire( '../../../lib/utils/automated-tests/parsearguments', { '@ckeditor/ckeditor5-dev-utils': { logger() { return stubs.logger; }, tools: stubs.tools - } + }, + 'fs': stubs.fs } ); } ); afterEach( () => { sandbox.restore(); + mockery.disable(); } ); it( 'replaces kebab-case strings with camelCase values', () => { @@ -172,10 +194,10 @@ describe( 'parseArguments()', () => { 'returns an array of packages to tests when `--repositories` is specified ' + '(root directory check)', () => { - stubs.cwd.returns( '/home/project' ); + packageName = 'ckeditor5'; + + stubs.fs.statSync.withArgs( '/home/project/external' ).throws( 'ENOENT: no such file or directory' ); - stubs.tools.isDirectory.withArgs( '/home/project/external' ).returns( false ); - stubs.tools.readPackageName.withArgs( '/home/project' ).returns( 'ckeditor5' ); stubs.tools.getDirectories.withArgs( '/home/project/packages' ).returns( [ 'ckeditor5-core', 'ckeditor5-engine' @@ -199,12 +221,9 @@ describe( 'parseArguments()', () => { 'returns an array of packages to tests when `--repositories` is specified ' + '(external directory check)', () => { - stubs.cwd.returns( '/home/project' ); + packageName = 'foo'; - stubs.tools.isDirectory.withArgs( '/home/project/external' ).returns( true ); - stubs.tools.isDirectory.withArgs( '/home/project/external/ckeditor5' ).returns( true ); - - stubs.tools.readPackageName.withArgs( '/home/project' ).returns( 'foo' ); + stubs.fs.statSync.returns( { isDirectory: () => true } ); stubs.tools.getDirectories.withArgs( '/home/project/external/ckeditor5/packages' ).returns( [ 'ckeditor5-core', 'ckeditor5-engine' @@ -216,7 +235,6 @@ describe( 'parseArguments()', () => { ] ); expect( options.files ).to.deep.equal( [ 'core', 'engine' ] ); - expect( stubs.logger.warning.callCount ).to.equal( 0 ); } ); @@ -225,12 +243,10 @@ describe( 'parseArguments()', () => { 'returns an array of packages to tests when `--repositories` is specified ' + '(external directory check, specified repository does not exist)', () => { - stubs.cwd.returns( '/home/project' ); + packageName = 'foo'; - stubs.tools.isDirectory.withArgs( '/home/project/external' ).returns( true ); - stubs.tools.isDirectory.withArgs( '/home/project/external/ckeditor5' ).returns( false ); - - stubs.tools.readPackageName.withArgs( '/home/project' ).returns( 'foo' ); + stubs.fs.statSync.withArgs( '/home/project/external' ).returns( { isDirectory: () => true } ); + stubs.fs.statSync.withArgs( '/home/project/external/ckeditor5' ).throws( 'ENOENT: no such file or directory' ); const options = parseArguments( [ '--repositories', @@ -250,11 +266,9 @@ describe( 'parseArguments()', () => { 'returns an array of packages (unique list) to tests when `--repositories` is specified ' + '(root directory check + `--files` specified)', () => { - stubs.cwd.returns( '/home/project' ); - - stubs.tools.isDirectory.withArgs( '/home/project/external' ).returns( true ); + packageName = 'ckeditor5'; - stubs.tools.readPackageName.withArgs( '/home/project' ).returns( 'ckeditor5' ); + stubs.fs.statSync.withArgs( '/home/project/external' ).returns( { isDirectory: () => true } ); stubs.tools.getDirectories.withArgs( '/home/project/packages' ).returns( [ 'ckeditor5-core', 'ckeditor5-engine', @@ -276,12 +290,11 @@ describe( 'parseArguments()', () => { 'returns an array of packages to tests when `--repositories` is specified ' + '(root and external directories check)', () => { - stubs.cwd.returns( '/home/project' ); + packageName = 'ckeditor5'; - stubs.tools.isDirectory.withArgs( '/home/project/external' ).returns( true ); - stubs.tools.isDirectory.withArgs( '/home/project/external/foo' ).returns( true ); - stubs.tools.isDirectory.withArgs( '/home/project/external/bar' ).returns( true ); - stubs.tools.readPackageName.withArgs( '/home/project' ).returns( 'ckeditor5' ); + stubs.fs.statSync.withArgs( '/home/project/external' ).returns( { isDirectory: () => true } ); + stubs.fs.statSync.withArgs( '/home/project/external/foo' ).returns( { isDirectory: () => true } ); + stubs.fs.statSync.withArgs( '/home/project/external/bar' ).returns( { isDirectory: () => true } ); stubs.tools.getDirectories.withArgs( '/home/project/packages' ).returns( [ 'ckeditor5-core', 'ckeditor5-engine' diff --git a/packages/ckeditor5-dev-utils/lib/builds/getdllpluginwebpackconfig.js b/packages/ckeditor5-dev-utils/lib/builds/getdllpluginwebpackconfig.js index 2759e42e1..306b259b7 100644 --- a/packages/ckeditor5-dev-utils/lib/builds/getdllpluginwebpackconfig.js +++ b/packages/ckeditor5-dev-utils/lib/builds/getdllpluginwebpackconfig.js @@ -9,7 +9,6 @@ const path = require( 'path' ); const fs = require( 'fs-extra' ); const { CKEditorTranslationsPlugin } = require( '@ckeditor/ckeditor5-dev-translations' ); const bundler = require( '../bundler' ); -const tools = require( '../tools' ); const loaders = require( '../loaders' ); /** @@ -33,7 +32,7 @@ module.exports = function getDllPluginWebpackConfig( webpack, options ) { // See: https://github.com/ckeditor/ckeditor5/issues/13136. const TerserPlugin = require( 'terser-webpack-plugin' ); - const packageName = tools.readPackageName( options.packagePath ); + const { name: packageName } = require( path.join( options.packagePath, 'package.json' ) ); const langDirExists = fs.existsSync( path.join( options.packagePath, 'lang' ) ); const indexJsExists = fs.existsSync( path.join( options.packagePath, 'src', 'index.js' ) ); diff --git a/packages/ckeditor5-dev-utils/lib/git.js b/packages/ckeditor5-dev-utils/lib/git.js deleted file mode 100644 index 4be1d2333..000000000 --- a/packages/ckeditor5-dev-utils/lib/git.js +++ /dev/null @@ -1,185 +0,0 @@ -/** - * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved. - * For licensing, see LICENSE.md. - */ - -'use strict'; - -const tools = require( './tools' ); -const defaultOrigin = 'origin'; - -module.exports = { - /** - * Parses GitHub URL. Extracts used server, repository and branch. - * - * @param {String} url GitHub URL from package.json file. - * @returns {Object} urlInfo - * @returns {String} urlInfo.server - * @returns {String} urlInfo.repository - * @returns {String} urlInfo.user - * @returns {String} urlInfo.name - * @returns {String} urlInfo.branch - */ - parseRepositoryUrl( url ) { - const regexp = /^((?:git@|(?:https?|git):\/\/)github\.com(?:\/|:))?(([\w-]+)\/([\w-]+(?:\.git)?))(?:#([\w-/.]+))?$/; - const match = url.match( regexp ); - - if ( !match ) { - return null; - } - - const server = match[ 1 ] || 'git@github.com:'; - const repository = match[ 2 ]; - const user = match[ 3 ]; - const branch = match[ 5 ] || 'master'; - let name = match[ 4 ]; - - name = /\.git$/.test( name ) ? name.slice( 0, -4 ) : name; - - return { - server, - repository, - branch, - user, - name - }; - }, - - /** - * Clones repository to workspace. - * - * @param {Object} urlInfo Parsed URL object from {@link #parseRepositoryUrl}. - * @param {String} workspacePath Path to the workspace location where repository will be cloned. - */ - cloneRepository( urlInfo, workspacePath ) { - const cloneCommands = [ - `cd ${ workspacePath }`, - `git clone ${ urlInfo.server + urlInfo.repository }` - ]; - - tools.shExec( cloneCommands.join( ' && ' ) ); - }, - - /** - * Checks out branch on selected repository. - * - * @param {String} repositoryLocation Absolute path to repository. - * @param {String} branchName Name of the branch to checkout. - */ - checkout( repositoryLocation, branchName ) { - const checkoutCommands = [ - `cd ${ repositoryLocation }`, - `git checkout ${ branchName }` - ]; - - tools.shExec( checkoutCommands.join( ' && ' ) ); - }, - - /** - * Pulls specified branch from origin. - * - * @param {String} repositoryLocation Absolute path to repository. - * @param {String} branchName Branch name to pull. - */ - pull( repositoryLocation, branchName ) { - const pullCommands = [ - `cd ${ repositoryLocation }`, - `git pull ${ defaultOrigin } ${ branchName }` - ]; - - tools.shExec( pullCommands.join( ' && ' ) ); - }, - - /** - * Fetch all branches from each origin on selected repository. - * - * @param {String} repositoryLocation - */ - fetchAll( repositoryLocation ) { - const fetchCommands = [ - `cd ${ repositoryLocation }`, - 'git fetch --all' - ]; - - tools.shExec( fetchCommands.join( ' && ' ) ); - }, - - /** - * Initializes new repository, adds and merges CKEditor5 boilerplate project. - * - * @param {String} repositoryPath Absolute path where repository should be created. - */ - initializeRepository( repositoryPath ) { - tools.shExec( `git init ${ repositoryPath }` ); - }, - - /** - * Returns Git status of repository stored under specified path. It runs `git status --porcelain -sb` command. - * - * @param {String} repositoryPath Absolute path to repository. - * @returns {String} Executed command's result. - */ - getStatus( repositoryPath ) { - return tools.shExec( `cd ${ repositoryPath } && git status --porcelain -sb`, { verbosity: 'error' } ); - }, - - /** - * Creates initial commit on repository under specified path. - * - * @param {String} pluginName - * @param {String} repositoryPath - */ - initialCommit( pluginName, repositoryPath ) { - const commitCommands = [ - `cd ${ repositoryPath }`, - 'git add .', - `git commit -m "Initial commit for ${ pluginName }."` - ]; - - tools.shExec( commitCommands.join( ' && ' ) ); - }, - - /** - * Adds remote to repository under specified path. - * - * @param {String} repositoryPath - * @param {String} gitHubPath - */ - addRemote( repositoryPath, gitHubPath ) { - const addRemoteCommands = [ - `cd ${ repositoryPath }`, - `git remote add ${ defaultOrigin } git@github.com:${ gitHubPath }.git` - ]; - - tools.shExec( addRemoteCommands.join( ' && ' ) ); - }, - - /* - * Creates commit on repository under specified path. - * - * @param {String} message - * @param {String} repositoryPath - */ - commit( message, repositoryPath ) { - const commitCommands = [ - `cd ${ repositoryPath }`, - `git commit --all --message "${ message }"` - ]; - - tools.shExec( commitCommands.join( ' && ' ) ); - }, - - /** - * Pushes changes to repository's default location. - * - * @param {String} repositoryPath - */ - push( repositoryPath ) { - const pushCommands = [ - `cd ${ repositoryPath }`, - 'git push' - ]; - - tools.shExec( pushCommands.join( ' && ' ) ); - } -}; diff --git a/packages/ckeditor5-dev-utils/lib/index.js b/packages/ckeditor5-dev-utils/lib/index.js index a80b29e32..12dfc2017 100644 --- a/packages/ckeditor5-dev-utils/lib/index.js +++ b/packages/ckeditor5-dev-utils/lib/index.js @@ -6,12 +6,10 @@ 'use strict'; module.exports = { - git: require( './git' ), logger: require( './logger' ), tools: require( './tools' ), loaders: require( './loaders' ), stream: require( './stream' ), - workspace: require( './workspace' ), bundler: require( './bundler/index' ), builds: require( './builds/index' ), styles: require( './styles/index' ) diff --git a/packages/ckeditor5-dev-utils/lib/tools.js b/packages/ckeditor5-dev-utils/lib/tools.js index c579d4541..3fae17989 100644 --- a/packages/ckeditor5-dev-utils/lib/tools.js +++ b/packages/ckeditor5-dev-utils/lib/tools.js @@ -6,8 +6,6 @@ 'use strict'; const chalk = require( 'chalk' ); -const path = require( 'path' ); -const fs = require( 'fs-extra' ); const createSpinner = require( './tools/createspinner' ); module.exports = { @@ -84,23 +82,6 @@ module.exports = { } }, - /** - * Links directory located in source path to directory located in destination path. - * @param {String} source - * @param {String} destination - */ - linkDirectories( source, destination ) { - const fs = require( 'fs' ); - // Remove destination directory if exists. - if ( this.isSymlink( destination ) ) { - this.removeSymlink( destination ); - } else if ( this.isDirectory( destination ) ) { - this.shExec( `rm -rf ${ destination }` ); - } - - fs.symlinkSync( source, destination, 'dir' ); - }, - /** * Returns array with all directories under specified path. * @@ -111,58 +92,19 @@ module.exports = { const fs = require( 'fs' ); const pth = require( 'path' ); + const isDirectory = path => { + try { + return fs.statSync( path ).isDirectory(); + } catch ( e ) { + return false; + } + }; + return fs.readdirSync( path ).filter( item => { - return this.isDirectory( pth.join( path, item ) ); + return isDirectory( pth.join( path, item ) ); } ); }, - /** - * Returns true if path points to existing directory. - * - * @param {String} path - * @returns {Boolean} - */ - isDirectory( path ) { - const fs = require( 'fs' ); - - try { - return fs.statSync( path ).isDirectory(); - } catch ( e ) { - return false; - } - }, - - /** - * Returns true if path points to existing file. - * - * @param {String} path - * @returns {Boolean} - */ - isFile( path ) { - const fs = require( 'fs' ); - - try { - return fs.statSync( path ).isFile(); - } catch ( e ) { - return false; - } - }, - - /** - * Returns true if path points to symbolic link. - * - * @param {String} path - */ - isSymlink( path ) { - const fs = require( 'fs' ); - - try { - return fs.lstatSync( path ).isSymbolicLink(); - } catch ( e ) { - return false; - } - }, - /** * Updates JSON file under specified path. * @param {String} path Path to file on disk. @@ -177,200 +119,5 @@ module.exports = { json = updateFunction( json ); fs.writeFileSync( path, JSON.stringify( json, null, 2 ) + '\n', 'utf-8' ); - }, - - /** - * Reinserts all object's properties in alphabetical order (character's Unicode value). - * Used for JSON.stringify method which takes keys in insertion order. - * - * @param { Object } obj - * @returns { Object } Same object with sorted keys. - */ - sortObject( obj ) { - Object.keys( obj ).sort().forEach( key => { - const val = obj[ key ]; - delete obj[ key ]; - obj[ key ] = val; - } ); - - return obj; - }, - - /** - * Returns name of the NPM module located under provided path. - * - * @param {String} modulePath Path to NPM module. - */ - readPackageName( modulePath ) { - const fs = require( 'fs' ); - const path = require( 'path' ); - const packageJSONPath = path.join( modulePath, 'package.json' ); - - if ( !this.isFile( packageJSONPath ) ) { - return null; - } - - const contents = fs.readFileSync( packageJSONPath, 'utf-8' ); - const json = JSON.parse( contents ); - - return json.name || null; - }, - - /** - * Calls `npm install` command in specified path. - * - * @param {String} path - */ - npmInstall( path ) { - this.shExec( `cd ${ path } && npm install` ); - }, - - /** - * Calls `npm uninstall ` command in specified path. - * - * @param {String} path - * @param {String} name - */ - npmUninstall( path, name ) { - this.shExec( `cd ${ path } && npm uninstall ${ name }` ); - }, - - /** - * Calls `npm update --dev` command in specified path. - * - * @param {String} path - */ - npmUpdate( path ) { - this.shExec( `cd ${ path } && npm update --dev` ); - }, - - /** - * - * Copies file located under `inputPath` to `outputPath`. Optionally replaces contents of the file using provided - * `replace` object. - * - * // Each occurrence of `{{appName}}` inside README.md will be changed to `ckeditor5`. - * tools.copyTemplateFile( '/path/to/README.md', '/new/path/to/README.md', { '{{AppName}}': 'ckeditor5' } ); - * - * @param {String} inputPath Path to input file. - * @param {String} outputPath Path to output file. - * @param {Object} [replace] Object with data to fill template. Method will take object's keys and replace their - * occurrences with value stored under that key. - */ - copyTemplateFile( inputPath, outputPath, replace ) { - const fs = require( 'fs-extra' ); - const path = require( 'path' ); - - // Create destination directory if one not exists. - fs.ensureDirSync( path.dirname( outputPath ) ); - - // If there is nothing to modify - just copy the file. - if ( !replace ) { - fs.copySync( inputPath, outputPath ); - - return; - } - - // When replace object is passed - modify file on the fly. - const regexpList = []; - - for ( const variableName in replace ) { - regexpList.push( variableName ); - } - - // Create one regexp for all variables to replace. - const regexp = new RegExp( regexpList.join( '|' ), 'g' ); - - // Read and modify. - const inputData = fs.readFileSync( inputPath, 'utf8' ); - const modifiedData = inputData.replace( regexp, matched => replace[ matched ] ); - - // Save. - fs.writeFileSync( outputPath, modifiedData, 'utf8' ); - }, - - /** - * Copies a file. Takes care of creating parent directory if it doesn't exist. - * - * @param {String} from Source path. - * @param {String} to Destination path (directory with file name). - * @returns {Promise} - */ - copyFile( from, to ) { - return new Promise( ( resolve, reject ) => { - fs.readFile( from, 'utf8', ( err, data ) => { - if ( err ) { - return reject( err ); - } - - fs.outputFile( to, data, err => { - if ( err ) { - return reject( err ); - } - - return resolve(); - } ); - } ); - } ); - }, - - /** - * Executes 'npm view' command for provided module name and returns Git url if one is found. Returns null if - * module cannot be found. - * - * @param {String} name Name of the module. - * @returns {*} - */ - getGitUrlFromNpm( name ) { - try { - const info = JSON.parse( this.shExec( `npm view ${ name } repository --json`, false ) ); - - if ( info && info.type == 'git' ) { - return info.url; - } - } catch ( error ) { - // Throw error only when different than E404. - if ( error.message.indexOf( 'npm ERR! code E404' ) == -1 ) { - throw error; - } - } - - return null; - }, - - /** - * Unlinks symbolic link under specified path. - * - * @param {String} path - */ - removeSymlink( path ) { - const fs = require( 'fs' ); - fs.unlinkSync( path ); - }, - - /** - * Removes files and directories specified by `glob` starting from `rootDir` - * and gently informs about deletion. - * - * @param {String} rootDir The path to the root directory (i.e. "dist/"). - * @param {String} glob Glob specifying what to clean. - * @param {Object} options - * @param {String} options.verbosity='info' A level of the verbosity for logger. - * @returns {Promise} - */ - clean( rootDir, glob, options = { verbosity: 'info' } ) { - const del = require( 'del' ); - - const joinedPath = path.join( rootDir, glob ); - const normalizedPath = joinedPath.split( '\\' ).join( '/' ); - - return del( normalizedPath ) - .then( paths => { - const log = require( './logger' )( options.verbosity ); - - paths.forEach( p => { - log.info( `Deleted file '${ chalk.cyan( p ) }'.` ); - } ); - } ); } }; diff --git a/packages/ckeditor5-dev-utils/lib/workspace.js b/packages/ckeditor5-dev-utils/lib/workspace.js deleted file mode 100644 index ffed637e0..000000000 --- a/packages/ckeditor5-dev-utils/lib/workspace.js +++ /dev/null @@ -1,108 +0,0 @@ -/** - * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved. - * For licensing, see LICENSE.md. - */ - -'use strict'; - -const path = require( 'path' ); -const tools = require( './tools' ); -const git = require( './git' ); - -const dependencyRegExp = /^ckeditor5-/; - -module.exports = { - /** - * Returns dependencies that starts with `ckeditor5-`, and have valid, short GitHub url. Returns `null` if no - * dependencies are found. - * - * @param {Object} dependencies Dependencies object loaded from `package.json` file. - * @returns {Object|null} - */ - getDependencies( dependencies ) { - let result = null; - - if ( dependencies ) { - Object.keys( dependencies ).forEach( key => { - if ( dependencyRegExp.test( key ) ) { - if ( result === null ) { - result = {}; - } - - result[ key ] = dependencies[ key ]; - } - } ); - } - - return result; - }, - - /** - * Returns all directories under specified path that match `ckeditor5-*` pattern. - * - * @param {String} path - * @returns {Array.} - */ - getDirectories( path ) { - return tools.getDirectories( path ).filter( dir => { - return dependencyRegExp.test( dir ); - } ); - }, - - /** - * Returns a list of symbolic links to directories with names starting with `ckeditor5-` prefix. - * - * @param {String} path Path to directory, - * @returns {Array} Array with directories names. - */ - getSymlinks( path ) { - const fs = require( 'fs' ); - const pth = require( 'path' ); - - return fs.readdirSync( path ).filter( item => { - const fullPath = pth.join( path, item ); - - return dependencyRegExp.test( item ) && tools.isSymlink( fullPath ); - } ); - }, - - /** - * Returns an array with information about `ckeditor5-*` directories in development mode. - * - * @param {String} workspacePath Absolute path to workspace. - * @param {Object} packageJSON Contents of `ckeditor5` repo `package.json` file. - * @param {String} ckeditor5Path Absolute path to ckeditor5 root directory. - * @param {Boolean} includeRoot Include main `ckeditor5` package. - * @returns {Array.} - */ - getDevDirectories( workspacePath, packageJSON, ckeditor5Path, includeRoot ) { - const directories = this.getDirectories( workspacePath ); - const dependencies = this.getDependencies( packageJSON.dependencies ); - - const devDirectories = []; - - for ( const dependency in dependencies ) { - const repositoryURL = dependencies[ dependency ]; - const urlInfo = git.parseRepositoryUrl( repositoryURL ); - const repositoryPath = path.posix.join( workspacePath, dependency ); - - // Check if repository's directory already exists. - if ( directories.indexOf( urlInfo.name ) > -1 ) { - devDirectories.push( { - repositoryPath, - repositoryURL - } ); - } - } - - if ( includeRoot ) { - // Add root dependency and directory. - devDirectories.unshift( { - repositoryPath: ckeditor5Path, - repositoryURL: 'ckeditor/ckeditor5' - } ); - } - - return devDirectories; - } -}; diff --git a/packages/ckeditor5-dev-utils/tests/builds/getdllpluginwebpackconfig.js b/packages/ckeditor5-dev-utils/tests/builds/getdllpluginwebpackconfig.js index 111576c32..303f379f3 100644 --- a/packages/ckeditor5-dev-utils/tests/builds/getdllpluginwebpackconfig.js +++ b/packages/ckeditor5-dev-utils/tests/builds/getdllpluginwebpackconfig.js @@ -13,7 +13,7 @@ const TerserPlugin = require( 'terser-webpack-plugin' ); const expect = chai.expect; describe( 'builds/getDllPluginWebpackConfig()', () => { - let sandbox, stubs, getDllPluginWebpackConfig; + let sandbox, stubs, getDllPluginWebpackConfig, packageName; const manifest = { content: { @@ -33,9 +33,6 @@ describe( 'builds/getDllPluginWebpackConfig()', () => { sandbox = sinon.createSandbox(); stubs = { - tools: { - readPackageName: sandbox.stub() - }, fs: { existsSync: sandbox.stub() }, @@ -58,10 +55,16 @@ describe( 'builds/getDllPluginWebpackConfig()', () => { warnOnUnregistered: false } ); + packageName = '@ckeditor/ckeditor5-dev'; + mockery.registerMock( 'fs-extra', stubs.fs ); - mockery.registerMock( '../tools', stubs.tools ); mockery.registerMock( '../loaders', stubs.loaders ); mockery.registerMock( '/manifest/path', manifest ); + mockery.registerMock( '/package/path/package.json', { + get name() { + return packageName; + } + } ); getDllPluginWebpackConfig = require( '../../lib/builds/getdllpluginwebpackconfig' ); } ); @@ -73,8 +76,6 @@ describe( 'builds/getDllPluginWebpackConfig()', () => { } ); it( 'returns the webpack configuration in production mode by default', () => { - stubs.tools.readPackageName.returns( '@ckeditor/ckeditor5-dev' ); - const webpackConfig = getDllPluginWebpackConfig( stubs.webpack, { packagePath: '/package/path', themePath: '/theme/path', @@ -100,7 +101,7 @@ describe( 'builds/getDllPluginWebpackConfig()', () => { } ); it( 'transforms package with many dashes in its name', () => { - stubs.tools.readPackageName.returns( '@ckeditor/ckeditor5-html-embed' ); + packageName = '@ckeditor/ckeditor5-html-embed'; const webpackConfig = getDllPluginWebpackConfig( stubs.webpack, { packagePath: '/package/path', @@ -114,8 +115,6 @@ describe( 'builds/getDllPluginWebpackConfig()', () => { } ); it( 'does not minify the destination file when in dev mode', () => { - stubs.tools.readPackageName.returns( '@ckeditor/ckeditor5-dev' ); - const webpackConfig = getDllPluginWebpackConfig( stubs.webpack, { packagePath: '/package/path', themePath: '/theme/path', @@ -129,8 +128,6 @@ describe( 'builds/getDllPluginWebpackConfig()', () => { } ); it( 'should not export any library by default', () => { - stubs.tools.readPackageName.returns( '@ckeditor/ckeditor5-dev' ); - const webpackConfig = getDllPluginWebpackConfig( stubs.webpack, { packagePath: '/package/path', themePath: '/theme/path', @@ -141,7 +138,6 @@ describe( 'builds/getDllPluginWebpackConfig()', () => { } ); it( 'uses index.ts entry file by default', () => { - stubs.tools.readPackageName.returns( '@ckeditor/ckeditor5-dev' ); stubs.fs.existsSync.callsFake( file => file == '/package/path/src/index.ts' ); const webpackConfig = getDllPluginWebpackConfig( stubs.webpack, { @@ -154,7 +150,6 @@ describe( 'builds/getDllPluginWebpackConfig()', () => { } ); it( 'uses index.js entry file if exists (over its TS version)', () => { - stubs.tools.readPackageName.returns( '@ckeditor/ckeditor5-dev' ); stubs.fs.existsSync.callsFake( file => file == '/package/path/src/index.js' ); const webpackConfig = getDllPluginWebpackConfig( stubs.webpack, { @@ -167,7 +162,6 @@ describe( 'builds/getDllPluginWebpackConfig()', () => { } ); it( 'loads JavaScript files over TypeScript when building for a JavaScript package', () => { - stubs.tools.readPackageName.returns( '@ckeditor/ckeditor5-dev' ); stubs.fs.existsSync.callsFake( file => file == '/package/path/src/index.js' ); const webpackConfig = getDllPluginWebpackConfig( stubs.webpack, { @@ -181,8 +175,6 @@ describe( 'builds/getDllPluginWebpackConfig()', () => { describe( '#plugins', () => { it( 'loads the webpack.DllReferencePlugin plugin', () => { - stubs.tools.readPackageName.returns( '@ckeditor/ckeditor5-dev' ); - const webpackConfig = getDllPluginWebpackConfig( stubs.webpack, { packagePath: '/package/path', themePath: '/theme/path', @@ -199,7 +191,6 @@ describe( 'builds/getDllPluginWebpackConfig()', () => { } ); it( 'loads the CKEditorTranslationsPlugin plugin when lang dir exists', () => { - stubs.tools.readPackageName.returns( '@ckeditor/ckeditor5-dev' ); stubs.fs.existsSync.returns( true ); const webpackConfig = getDllPluginWebpackConfig( stubs.webpack, { @@ -223,7 +214,6 @@ describe( 'builds/getDllPluginWebpackConfig()', () => { } ); it( 'does not load the CKEditorTranslationsPlugin plugin when lang dir does not exist', () => { - stubs.tools.readPackageName.returns( '@ckeditor/ckeditor5-dev' ); stubs.fs.existsSync.returns( false ); const webpackConfig = getDllPluginWebpackConfig( stubs.webpack, { @@ -241,10 +231,12 @@ describe( 'builds/getDllPluginWebpackConfig()', () => { } ); describe( '#loaders', () => { + beforeEach( () => { + packageName = '@ckeditor/ckeditor5-html-embed'; + } ); + describe( 'getTypeScriptLoader()', () => { it( 'it should use the default tsconfig.json if the "options.tsconfigPath" option is not specified', () => { - stubs.tools.readPackageName.returns( '@ckeditor/ckeditor5-html-embed' ); - getDllPluginWebpackConfig( stubs.webpack, { packagePath: '/package/path', themePath: '/theme/path', @@ -258,8 +250,6 @@ describe( 'builds/getDllPluginWebpackConfig()', () => { } ); it( 'it should the specified "options.tsconfigPath" value', () => { - stubs.tools.readPackageName.returns( '@ckeditor/ckeditor5-html-embed' ); - getDllPluginWebpackConfig( stubs.webpack, { packagePath: '/package/path', themePath: '/theme/path', @@ -276,8 +266,6 @@ describe( 'builds/getDllPluginWebpackConfig()', () => { describe( 'getIconsLoader()', () => { it( 'it should get the loader', () => { - stubs.tools.readPackageName.returns( '@ckeditor/ckeditor5-html-embed' ); - getDllPluginWebpackConfig( stubs.webpack, { packagePath: '/package/path', themePath: '/theme/path', @@ -293,8 +281,6 @@ describe( 'builds/getDllPluginWebpackConfig()', () => { describe( 'getStylesLoader()', () => { it( 'it should get the loader', () => { - stubs.tools.readPackageName.returns( '@ckeditor/ckeditor5-html-embed' ); - getDllPluginWebpackConfig( stubs.webpack, { packagePath: '/package/path', themePath: '/theme/path', diff --git a/packages/ckeditor5-dev-utils/tests/git.js b/packages/ckeditor5-dev-utils/tests/git.js deleted file mode 100644 index 347c7c1a6..000000000 --- a/packages/ckeditor5-dev-utils/tests/git.js +++ /dev/null @@ -1,275 +0,0 @@ -/** - * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved. - * For licensing, see LICENSE.md. - */ - -'use strict'; - -let sandbox; -const git = require( '../lib/git' ); -const chai = require( 'chai' ); -const sinon = require( 'sinon' ); -const tools = require( '../lib/tools' ); -const expect = chai.expect; - -describe( 'utils', () => { - beforeEach( () => { - sandbox = sinon.createSandbox(); - } ); - - afterEach( () => { - sandbox.restore(); - } ); - - describe( 'git', () => { - describe( 'parseRepositoryUrl', () => { - it( 'should be defined', () => expect( git.parseRepositoryUrl ).to.be.a( 'function' ) ); - - it( 'should parse short GitHub URL ', () => { - const urlInfo = git.parseRepositoryUrl( 'ckeditor/ckeditor5-core' ); - - expect( urlInfo.server ).to.equal( 'git@github.com:' ); - expect( urlInfo.repository ).to.equal( 'ckeditor/ckeditor5-core' ); - expect( urlInfo.user ).to.equal( 'ckeditor' ); - expect( urlInfo.name ).to.equal( 'ckeditor5-core' ); - expect( urlInfo.branch ).to.equal( 'master' ); - } ); - - it( 'should parse short GitHub URL with provided branch ', () => { - const urlInfo = git.parseRepositoryUrl( 'ckeditor/ckeditor5-core#experimental' ); - - expect( urlInfo.server ).to.equal( 'git@github.com:' ); - expect( urlInfo.repository ).to.equal( 'ckeditor/ckeditor5-core' ); - expect( urlInfo.user ).to.equal( 'ckeditor' ); - expect( urlInfo.name ).to.equal( 'ckeditor5-core' ); - expect( urlInfo.branch ).to.equal( 'experimental' ); - } ); - - it( 'should parse full GitHub URL (http)', () => { - const urlInfo = git.parseRepositoryUrl( 'http://github.com/ckeditor/ckeditor5-core.git' ); - - expect( urlInfo.server ).to.equal( 'http://github.com/' ); - expect( urlInfo.repository ).to.equal( 'ckeditor/ckeditor5-core.git' ); - expect( urlInfo.user ).to.equal( 'ckeditor' ); - expect( urlInfo.name ).to.equal( 'ckeditor5-core' ); - expect( urlInfo.branch ).to.equal( 'master' ); - } ); - - it( 'should parse full GitHub URL (http) with provided branch', () => { - const urlInfo = git.parseRepositoryUrl( 'http://github.com/ckeditor/ckeditor5-core.git#experimental' ); - - expect( urlInfo.server ).to.equal( 'http://github.com/' ); - expect( urlInfo.repository ).to.equal( 'ckeditor/ckeditor5-core.git' ); - expect( urlInfo.user ).to.equal( 'ckeditor' ); - expect( urlInfo.name ).to.equal( 'ckeditor5-core' ); - expect( urlInfo.branch ).to.equal( 'experimental' ); - } ); - - it( 'should parse full GitHub URL (https)', () => { - const urlInfo = git.parseRepositoryUrl( 'https://github.com/ckeditor/ckeditor5-core.git' ); - - expect( urlInfo.server ).to.equal( 'https://github.com/' ); - expect( urlInfo.repository ).to.equal( 'ckeditor/ckeditor5-core.git' ); - expect( urlInfo.user ).to.equal( 'ckeditor' ); - expect( urlInfo.name ).to.equal( 'ckeditor5-core' ); - expect( urlInfo.branch ).to.equal( 'master' ); - } ); - - it( 'should parse full GitHub URL (https) with provided branch', () => { - const urlInfo = git.parseRepositoryUrl( 'https://github.com/ckeditor/ckeditor5-core.git#t/122' ); - - expect( urlInfo.server ).to.equal( 'https://github.com/' ); - expect( urlInfo.repository ).to.equal( 'ckeditor/ckeditor5-core.git' ); - expect( urlInfo.user ).to.equal( 'ckeditor' ); - expect( urlInfo.name ).to.equal( 'ckeditor5-core' ); - expect( urlInfo.branch ).to.equal( 't/122' ); - } ); - - it( 'should parse full GitHub URL (git@)', () => { - const urlInfo = git.parseRepositoryUrl( 'git@github.com:ckeditor/ckeditor5-core.git' ); - - expect( urlInfo.server ).to.equal( 'git@github.com:' ); - expect( urlInfo.repository ).to.equal( 'ckeditor/ckeditor5-core.git' ); - expect( urlInfo.user ).to.equal( 'ckeditor' ); - expect( urlInfo.name ).to.equal( 'ckeditor5-core' ); - expect( urlInfo.branch ).to.equal( 'master' ); - } ); - - it( 'should parse full GitHub URL (git://)', () => { - const urlInfo = git.parseRepositoryUrl( 'git://github.com/ckeditor/ckeditor5-core.git' ); - - expect( urlInfo.server ).to.equal( 'git://github.com/' ); - expect( urlInfo.repository ).to.equal( 'ckeditor/ckeditor5-core.git' ); - expect( urlInfo.user ).to.equal( 'ckeditor' ); - expect( urlInfo.name ).to.equal( 'ckeditor5-core' ); - expect( urlInfo.branch ).to.equal( 'master' ); - } ); - - it( 'should parse full GitHub URL (git) with provided branch', () => { - const urlInfo = git.parseRepositoryUrl( 'git@github.com:ckeditor/ckeditor5-core.git#new-feature' ); - - expect( urlInfo.server ).to.equal( 'git@github.com:' ); - expect( urlInfo.repository ).to.equal( 'ckeditor/ckeditor5-core.git' ); - expect( urlInfo.user ).to.equal( 'ckeditor' ); - expect( urlInfo.name ).to.equal( 'ckeditor5-core' ); - expect( urlInfo.branch ).to.equal( 'new-feature' ); - } ); - - it( 'should return null if GitHub URL is not valid', () => { - let urlInfo = git.parseRepositoryUrl( 'https://ckeditor.com' ); - expect( urlInfo ).to.equal( null ); - - urlInfo = git.parseRepositoryUrl( 'https://github.com/info.html' ); - expect( urlInfo ).to.equal( null ); - } ); - - it( 'should parse short GitHub URL with provided tag', () => { - const urlInfo = git.parseRepositoryUrl( 'ckeditor/ckeditor5-core#v1.0.0' ); - - expect( urlInfo.server ).to.equal( 'git@github.com:' ); - expect( urlInfo.repository ).to.equal( 'ckeditor/ckeditor5-core' ); - expect( urlInfo.user ).to.equal( 'ckeditor' ); - expect( urlInfo.name ).to.equal( 'ckeditor5-core' ); - expect( urlInfo.branch ).to.equal( 'v1.0.0' ); - } ); - } ); - - describe( 'cloneRepository', () => { - it( 'should be defined', () => expect( git.cloneRepository ).to.be.a( 'function' ) ); - - it( 'should call clone commands', () => { - const shExecStub = sandbox.stub( tools, 'shExec' ); - const workspacePath = '/path/to/workspace/'; - const urlInfo = git.parseRepositoryUrl( 'git@github.com:ckeditor/ckeditor5-core#new-feature' ); - const cloneCommands = `cd ${ workspacePath } && git clone ${ urlInfo.server + urlInfo.repository }`; - - git.cloneRepository( urlInfo, workspacePath ); - - expect( shExecStub.calledOnce ).to.equal( true ); - expect( shExecStub.firstCall.args[ 0 ] ).to.equal( cloneCommands ); - } ); - } ); - - describe( 'checkout', () => { - it( 'should be defined', () => expect( git.checkout ).to.be.a( 'function' ) ); - - it( 'should call checkout commands', () => { - const shExecStub = sandbox.stub( tools, 'shExec' ); - const repositoryLocation = 'path/to/repository'; - const branchName = 'branch-to-checkout'; - const checkoutCommands = [ - `cd ${ repositoryLocation }`, - `git checkout ${ branchName }` - ].join( ' && ' ); - - git.checkout( repositoryLocation, branchName ); - - expect( shExecStub.calledOnce ).to.equal( true ); - expect( shExecStub.firstCall.args[ 0 ] ).to.equal( checkoutCommands ); - } ); - } ); - - describe( 'pull', () => { - it( 'should be defined', () => expect( git.pull ).to.be.a( 'function' ) ); - - it( 'should call pull commands', () => { - const shExecStub = sandbox.stub( tools, 'shExec' ); - const repositoryLocation = 'path/to/repository'; - const branchName = 'branch-to-pull'; - const pullCommands = `cd ${ repositoryLocation } && git pull origin ${ branchName }`; - - git.pull( repositoryLocation, branchName ); - - expect( shExecStub.calledOnce ).to.equal( true ); - expect( shExecStub.firstCall.args[ 0 ] ).to.equal( pullCommands ); - } ); - } ); - - describe( 'fetchAll', () => { - it( 'should be defined', () => expect( git.fetchAll ).to.be.a( 'function' ) ); - - it( 'should call fetch commands', () => { - const shExecStub = sandbox.stub( tools, 'shExec' ); - const repositoryLocation = 'path/to/repository'; - const fetchCommands = `cd ${ repositoryLocation } && git fetch --all`; - - git.fetchAll( repositoryLocation ); - - expect( shExecStub.calledOnce ).to.be.equal( true ); - expect( shExecStub.firstCall.args[ 0 ] ).to.be.equal( fetchCommands ); - } ); - } ); - - describe( 'initializeRepository', () => { - it( 'should be defined', () => expect( git.initializeRepository ).to.be.a( 'function' ) ); - - it( 'should call initialize commands', () => { - const shExecStub = sandbox.stub( tools, 'shExec' ); - const repositoryLocation = 'path/to/repository'; - const initializeCommands = [ - `git init ${ repositoryLocation }` - ]; - - git.initializeRepository( repositoryLocation ); - - expect( shExecStub.calledOnce ).to.equal( true ); - expect( shExecStub.firstCall.args[ 0 ] ).to.equal( initializeCommands.join( ' && ' ) ); - } ); - } ); - - describe( 'getStatus', () => { - it( 'should be defined', () => expect( git.getStatus ).to.be.a( 'function' ) ); - - it( 'should call status command', () => { - const shExecStub = sandbox.stub( tools, 'shExec' ); - const repositoryLocation = 'path/to/repository'; - const statusCommands = `cd ${ repositoryLocation } && git status --porcelain -sb`; - - git.getStatus( repositoryLocation ); - - expect( shExecStub.calledOnce ).to.equal( true ); - expect( shExecStub.firstCall.args[ 0 ] ).to.equal( statusCommands ); - expect( shExecStub.firstCall.args[ 1 ] ).to.deep.equal( { verbosity: 'error' } ); - } ); - } ); - - describe( 'initialCommit', () => { - it( 'should be defined', () => expect( git.initialCommit ).to.be.a( 'function' ) ); - - it( 'should execute commit commands', () => { - const shExecStub = sandbox.stub( tools, 'shExec' ); - const pluginName = 'ckeditor5-plugin-name'; - const repositoryPath = '/path/to/repo'; - const commitCommands = [ - `cd ${ repositoryPath }`, - 'git add .', - `git commit -m "Initial commit for ${ pluginName }."` - ]; - - git.initialCommit( pluginName, repositoryPath ); - - expect( shExecStub.calledOnce ).to.equal( true ); - expect( shExecStub.firstCall.args[ 0 ] ).to.equal( commitCommands.join( ' && ' ) ); - } ); - } ); - - describe( 'addRemote', () => { - it( 'should be defined', () => expect( git.addRemote ).to.be.a( 'function' ) ); - - it( 'should execute add remote commands', () => { - const shExecStub = sandbox.stub( tools, 'shExec' ); - const gitHubPath = 'ckeditor5/ckeditor5-plugin-name'; - const repositoryPath = '/path/to/repo'; - const addRemoteCommands = [ - `cd ${ repositoryPath }`, - `git remote add origin git@github.com:${ gitHubPath }.git` - ]; - - git.addRemote( repositoryPath, gitHubPath ); - - expect( shExecStub.calledOnce ).to.equal( true ); - expect( shExecStub.firstCall.args[ 0 ] ).to.equal( addRemoteCommands.join( ' && ' ) ); - } ); - } ); - } ); -} ); diff --git a/packages/ckeditor5-dev-utils/tests/tools.js b/packages/ckeditor5-dev-utils/tests/tools.js index 62061983f..3c707febc 100644 --- a/packages/ckeditor5-dev-utils/tests/tools.js +++ b/packages/ckeditor5-dev-utils/tests/tools.js @@ -10,7 +10,6 @@ const sinon = require( 'sinon' ); const expect = chai.expect; const tools = require( '../lib/tools' ); const path = require( 'path' ); -const fs = require( 'fs' ); const mockery = require( 'mockery' ); describe( 'utils', () => { @@ -211,63 +210,6 @@ describe( 'utils', () => { } ); } ); - describe( 'linkDirectories', () => { - it( 'should be defined', () => expect( tools.linkDirectories ).to.be.a( 'function' ) ); - - it( 'should link directories', () => { - const isSymlinkStub = sandbox.stub( tools, 'isSymlink' ).returns( false ); - const isDirectoryStub = sandbox.stub( tools, 'isDirectory' ).returns( false ); - const symlinkStub = sandbox.stub( fs, 'symlinkSync' ); - const source = '/source/dir'; - const destination = '/destination/dir'; - - tools.linkDirectories( source, destination ); - - expect( isDirectoryStub.calledOnce ).to.equal( true ); - expect( isSymlinkStub.calledOnce ).to.equal( true ); - expect( symlinkStub.calledOnce ).to.equal( true ); - expect( symlinkStub.firstCall.args[ 0 ] ).to.equal( source ); - expect( symlinkStub.firstCall.args[ 1 ] ).to.equal( destination ); - } ); - - it( 'should remove destination directory before linking', () => { - const shExecStub = sandbox.stub( tools, 'shExec' ); - const isSymlinkStub = sandbox.stub( tools, 'isSymlink' ).returns( false ); - const isDirectoryStub = sandbox.stub( tools, 'isDirectory' ).returns( true ); - const symlinkStub = sandbox.stub( fs, 'symlinkSync' ); - const source = '/source/dir'; - const destination = '/destination/dir'; - - tools.linkDirectories( source, destination ); - - expect( isDirectoryStub.calledOnce ).to.equal( true ); - expect( isSymlinkStub.calledOnce ).to.equal( true ); - expect( shExecStub.calledOnce ).to.equal( true ); - expect( symlinkStub.firstCall.args[ 0 ] ).to.equal( source ); - expect( symlinkStub.firstCall.args[ 1 ] ).to.equal( destination ); - } ); - - it( 'should unlink destination directory if symlink', () => { - const shExecStub = sandbox.stub( tools, 'shExec' ); - const isSymlinkStub = sandbox.stub( tools, 'isSymlink' ).returns( true ); - const removeSymlinkStub = sandbox.stub( tools, 'removeSymlink' ); - const isDirectoryStub = sandbox.stub( tools, 'isDirectory' ).returns( true ); - const symlinkStub = sandbox.stub( fs, 'symlinkSync' ); - const source = '/source/dir'; - const destination = '/destination/dir'; - - tools.linkDirectories( source, destination ); - - expect( isDirectoryStub.notCalled ).to.equal( true ); - expect( isSymlinkStub.calledOnce ).to.equal( true ); - expect( shExecStub.notCalled ).to.equal( true ); - expect( removeSymlinkStub.calledOnce ).to.equal( true ); - expect( removeSymlinkStub.firstCall.args[ 0 ] ).to.equal( destination ); - expect( symlinkStub.firstCall.args[ 0 ] ).to.equal( source ); - expect( symlinkStub.firstCall.args[ 1 ] ).to.equal( destination ); - } ); - } ); - describe( 'getDirectories', () => { it( 'should be defined', () => expect( tools.getDirectories ).to.be.a( 'function' ) ); @@ -275,116 +217,20 @@ describe( 'utils', () => { const fs = require( 'fs' ); const directories = [ 'dir1', 'dir2', 'dir3' ]; const readdirSyncStub = sandbox.stub( fs, 'readdirSync' ).returns( directories ); - const isDirectoryStub = sandbox.stub( tools, 'isDirectory' ).returns( true ); + const statSyncStub = sandbox.stub( fs, 'statSync' ).returns( { + isDirectory: () => { + return true; + } + } ); const dirPath = 'path'; tools.getDirectories( dirPath ); expect( readdirSyncStub.calledOnce ).to.equal( true ); - expect( isDirectoryStub.calledThrice ).to.equal( true ); - expect( isDirectoryStub.firstCall.args[ 0 ] ).to.equal( path.join( dirPath, directories[ 0 ] ) ); - expect( isDirectoryStub.secondCall.args[ 0 ] ).to.equal( path.join( dirPath, directories[ 1 ] ) ); - expect( isDirectoryStub.thirdCall.args[ 0 ] ).to.equal( path.join( dirPath, directories[ 2 ] ) ); - } ); - } ); - - describe( 'isDirectory', () => { - it( 'should be defined', () => expect( tools.isDirectory ).to.be.a( 'function' ) ); - - it( 'should return true if path points to directory', () => { - const fs = require( 'fs' ); - const statSyncStub = sandbox.stub( fs, 'statSync' ).returns( { isDirectory: () => true } ); - const path = 'path'; - - const result = tools.isDirectory( path ); - - expect( statSyncStub.calledOnce ).to.equal( true ); - expect( statSyncStub.firstCall.args[ 0 ] ).to.equal( path ); - expect( result ).to.equal( true ); - } ); - - it( 'should return false if path does not point to directory', () => { - const fs = require( 'fs' ); - const statSyncStub = sandbox.stub( fs, 'statSync' ).returns( { isDirectory: () => false } ); - const path = 'path'; - - const result = tools.isDirectory( path ); - - expect( statSyncStub.calledOnce ).to.equal( true ); - expect( statSyncStub.firstCall.args[ 0 ] ).to.equal( path ); - expect( result ).to.equal( false ); - } ); - - it( 'should return false if statSync method throws', () => { - const fs = require( 'fs' ); - const statSyncStub = sandbox.stub( fs, 'statSync' ).throws(); - const path = 'path'; - - const result = tools.isDirectory( path ); - - expect( statSyncStub.calledOnce ).to.equal( true ); - expect( statSyncStub.firstCall.args[ 0 ] ).to.equal( path ); - expect( result ).to.equal( false ); - } ); - } ); - - describe( 'isFile', () => { - it( 'should be defined', () => expect( tools.isFile ).to.be.a( 'function' ) ); - - it( 'should return true if path points to file', () => { - const fs = require( 'fs' ); - const statSyncStub = sandbox.stub( fs, 'statSync' ).returns( { isFile: () => true } ); - const path = 'path'; - - const result = tools.isFile( path ); - - expect( statSyncStub.calledOnce ).to.equal( true ); - expect( statSyncStub.firstCall.args[ 0 ] ).to.equal( path ); - expect( result ).to.equal( true ); - } ); - - it( 'should return false if path does not point to directory', () => { - const fs = require( 'fs' ); - const statSyncStub = sandbox.stub( fs, 'statSync' ).returns( { isFile: () => false } ); - const path = 'path'; - - const result = tools.isFile( path ); - - expect( statSyncStub.calledOnce ).to.equal( true ); - expect( statSyncStub.firstCall.args[ 0 ] ).to.equal( path ); - expect( result ).to.equal( false ); - } ); - - it( 'should return false if statSync method throws', () => { - const fs = require( 'fs' ); - const statSyncStub = sandbox.stub( fs, 'statSync' ).throws(); - const path = 'path'; - - const result = tools.isFile( path ); - - expect( statSyncStub.calledOnce ).to.equal( true ); - expect( statSyncStub.firstCall.args[ 0 ] ).to.equal( path ); - expect( result ).to.equal( false ); - } ); - } ); - - describe( 'isSymlink', () => { - it( 'should return true if path points to symbolic link', () => { - const path = 'path/to/file'; - const fs = require( 'fs' ); - sandbox.stub( fs, 'lstatSync' ).returns( { - isSymbolicLink: () => true - } ); - - expect( tools.isSymlink( path ) ).to.equal( true ); - } ); - - it( 'should return false if lstatSync throws', () => { - const path = 'path/to/file'; - const fs = require( 'fs' ); - sandbox.stub( fs, 'lstatSync' ).throws(); - - expect( tools.isSymlink( path ) ).to.equal( false ); + expect( statSyncStub.calledThrice ).to.equal( true ); + expect( statSyncStub.firstCall.args[ 0 ] ).to.equal( path.join( dirPath, directories[ 0 ] ) ); + expect( statSyncStub.secondCall.args[ 0 ] ).to.equal( path.join( dirPath, directories[ 1 ] ) ); + expect( statSyncStub.thirdCall.args[ 0 ] ).to.equal( path.join( dirPath, directories[ 2 ] ) ); } ); } ); @@ -408,286 +254,5 @@ describe( 'utils', () => { expect( writeFileStub.firstCall.args[ 1 ] ).to.equal( JSON.stringify( modifiedJSON, null, 2 ) + '\n' ); } ); } ); - - describe( 'sortObject', () => { - it( 'should be defined', () => expect( tools.sortObject ).to.be.a( 'function' ) ); - it( 'should reinsert object properties in alphabetical order', () => { - let obj = { - c: '', d: '', a: '', z: '' - }; - - const sorted = { - a: '', c: '', d: '', z: '' - }; - - obj = tools.sortObject( obj ); - - expect( JSON.stringify( obj ) ).to.equal( JSON.stringify( sorted ) ); - } ); - } ); - - describe( 'readPackageName', () => { - const modulePath = 'path/to/module'; - it( 'should read package name from NPM module', () => { - sandbox.stub( tools, 'isFile' ).returns( true ); - const fs = require( 'fs' ); - const name = 'module-name'; - sandbox.stub( fs, 'readFileSync' ).returns( JSON.stringify( { name } ) ); - - const result = tools.readPackageName( modulePath ); - - expect( result ).to.equal( name ); - } ); - - it( 'should return null if no package.json is found', () => { - sandbox.stub( tools, 'isFile' ).returns( false ); - - const result = tools.readPackageName( modulePath ); - - expect( result ).to.equal( null ); - } ); - - it( 'should return null if no name in package.json is provided', () => { - sandbox.stub( tools, 'isFile' ).returns( true ); - const fs = require( 'fs' ); - sandbox.stub( fs, 'readFileSync' ).returns( JSON.stringify( {} ) ); - - const result = tools.readPackageName( modulePath ); - - expect( result ).to.equal( null ); - } ); - } ); - - describe( 'npmInstall', () => { - it( 'should be defined', () => expect( tools.npmInstall ).to.be.a( 'function' ) ); - it( 'should execute npm install command', () => { - const shExecStub = sandbox.stub( tools, 'shExec' ); - const path = '/path/to/repository'; - - tools.npmInstall( path ); - - expect( shExecStub.calledOnce ).to.equal( true ); - expect( shExecStub.firstCall.args[ 0 ] ).to.equal( `cd ${ path } && npm install` ); - } ); - } ); - - describe( 'npmUpdate', () => { - it( 'should be defined', () => expect( tools.npmUpdate ).to.be.a( 'function' ) ); - it( 'should execute npm update command', () => { - const shExecStub = sandbox.stub( tools, 'shExec' ); - const path = '/path/to/repository'; - - tools.npmUpdate( path ); - - expect( shExecStub.calledOnce ).to.equal( true ); - expect( shExecStub.firstCall.args[ 0 ] ).to.equal( `cd ${ path } && npm update --dev` ); - } ); - } ); - - describe( 'npmUninstall', () => { - it( 'should be defined', () => expect( tools.npmUninstall ).to.be.a( 'function' ) ); - it( 'should execute npm uninstall command', () => { - const shExecStub = sandbox.stub( tools, 'shExec' ); - const path = '/path/to/repository'; - const moduleName = 'module-name'; - - tools.npmUninstall( path, moduleName ); - - expect( shExecStub.calledOnce ).to.equal( true ); - expect( shExecStub.firstCall.args[ 0 ] ).to.equal( `cd ${ path } && npm uninstall ${ moduleName }` ); - } ); - } ); - - describe( 'copyTemplateFile', () => { - it( 'should be defined', () => expect( tools.copyTemplateFile ).to.be.a( 'function' ) ); - - it( 'should copy files and replace provided texts', () => { - const path = require( 'path' ); - const fs = require( 'fs-extra' ); - const inputPath = '/path/to/file1.md'; - const outputPath = '/path/to/file2.md'; - - const readFileStub = sandbox.stub( fs, 'readFileSync' ); - const writeFileStub = sandbox.stub( fs, 'writeFileSync' ); - const ensureDirStub = sandbox.stub( fs, 'ensureDirSync' ); - - readFileStub.onFirstCall().returns( 'file data {{var1}}, {{var2}}' ); - - tools.copyTemplateFile( inputPath, outputPath, { - '{{var1}}': 'foo', - '{{var2}}': 'bar' - } ); - - sinon.assert.calledWithExactly( ensureDirStub, path.dirname( outputPath ) ); - sinon.assert.calledOnce( readFileStub ); - sinon.assert.calledWithExactly( readFileStub.firstCall, inputPath, 'utf8' ); - sinon.assert.calledOnce( writeFileStub ); - sinon.assert.calledWithExactly( writeFileStub.firstCall, outputPath, 'file data foo, bar', 'utf8' ); - } ); - - it( 'should copy files if no replace object is provided', () => { - const path = require( 'path' ); - const fs = require( 'fs-extra' ); - const inputPath = '/path/to/file1.md'; - const outputPath = '/path/to/file2.md'; - const copyFileStub = sandbox.stub( fs, 'copySync' ); - const ensureDirStub = sandbox.stub( fs, 'ensureDirSync' ); - - tools.copyTemplateFile( inputPath, outputPath ); - - sinon.assert.calledWithExactly( ensureDirStub, path.dirname( outputPath ) ); - sinon.assert.calledOnce( copyFileStub ); - sinon.assert.calledWithExactly( copyFileStub.firstCall, inputPath, outputPath ); - } ); - } ); - - describe( 'getGitUrlFromNpm', () => { - const repository = { - type: 'git', - url: 'git@github.com:ckeditor/ckeditor5-core' - }; - const moduleName = 'ckeditor5-core'; - - it( 'should be defined', () => expect( tools.getGitUrlFromNpm ).to.be.a( 'function' ) ); - it( 'should call npm view command', () => { - const shExecStub = sandbox.stub( tools, 'shExec' ).returns( JSON.stringify( repository ) ); - const url = tools.getGitUrlFromNpm( moduleName ); - - expect( shExecStub.calledOnce ).to.equal( true ); - expect( shExecStub.firstCall.args[ 0 ] ).to.equal( `npm view ${ moduleName } repository --json` ); - expect( url ).to.equal( repository.url ); - } ); - - it( 'should return null if module is not found', () => { - sandbox.stub( tools, 'shExec' ).throws( new Error( 'npm ERR! code E404' ) ); - const url = tools.getGitUrlFromNpm( moduleName ); - expect( url ).to.equal( null ); - } ); - - it( 'should return null if module has no repository information', () => { - sandbox.stub( tools, 'shExec' ).returns( JSON.stringify( {} ) ); - const url = tools.getGitUrlFromNpm( moduleName ); - expect( url ).to.equal( null ); - } ); - - it( 'should throw on other errors', () => { - const error = new Error( 'Random error.' ); - sandbox.stub( tools, 'shExec' ).throws( error ); - const getUrlSpy = sandbox.spy( tools, 'getGitUrlFromNpm' ); - - try { - tools.getGitUrlFromNpm( moduleName ); - } catch ( e ) { - expect( e ).to.equal( error ); - } - - expect( getUrlSpy.threw( error ) ).to.equal( true ); - } ); - } ); - - describe( 'removeSymlink', () => { - it( 'should unlink provided symlink', () => { - const fs = require( 'fs' ); - const unlinkStub = sandbox.stub( fs, 'unlinkSync' ); - const path = 'path/to/symlink'; - - tools.removeSymlink( path ); - - expect( unlinkStub.calledOnce ).to.equal( true ); - expect( unlinkStub.firstCall.args[ 0 ] ).to.equal( path ); - } ); - } ); - - describe( 'copyFile', () => { - const fs = require( 'fs-extra' ); - - it( 'rejects Promise when file does not exist', () => { - const readFileStub = sandbox.stub( fs, 'readFile' ).callsFake( ( from, to, callback ) => { - callback( 'Some error during readFile.' ); - } ); - - return tools.copyFile( '/tmp/not/existing/file.txt', '/tmp/file.txt' ) - .catch( err => { - expect( readFileStub.calledOnce ).to.equal( true ); - expect( readFileStub.firstCall.args[ 0 ] ).to.equal( '/tmp/not/existing/file.txt' ); - expect( err ).to.equal( 'Some error during readFile.' ); - } ); - } ); - - it( 'rejects Promise when file cannot be saved', () => { - const readFileStub = sandbox.stub( fs, 'readFile' ).callsFake( ( from, to, callback ) => { - callback( null, 'Some data.' ); - } ); - - const outputFileStub = sandbox.stub( fs, 'outputFile' ).callsFake( ( to, data, callback ) => { - callback( 'Some error during outputFile.' ); - } ); - - return tools.copyFile( '/tmp/directory/file.txt', '/tmp/file.txt' ) - .catch( err => { - expect( readFileStub.calledOnce ).to.equal( true ); - expect( readFileStub.firstCall.args[ 0 ] ).to.equal( '/tmp/directory/file.txt' ); - expect( outputFileStub.calledOnce ).to.equal( true ); - expect( outputFileStub.firstCall.args[ 0 ] ).to.equal( '/tmp/file.txt' ); - expect( outputFileStub.firstCall.args[ 1 ] ).to.equal( 'Some data.' ); - - expect( err ).to.equal( 'Some error during outputFile.' ); - } ); - } ); - - it( 'resolves Promise when file was copied', () => { - const readFileStub = sandbox.stub( fs, 'readFile' ).callsFake( ( from, to, callback ) => { - callback( null, 'Some data.' ); - } ); - - const outputFileStub = sandbox.stub( fs, 'outputFile' ).callsFake( ( to, data, callback ) => { - callback( null ); - } ); - - return tools.copyFile( '/tmp/directory/file.txt', '/tmp/file.txt' ) - .then( () => { - expect( readFileStub.calledOnce ).to.equal( true ); - expect( readFileStub.firstCall.args[ 0 ] ).to.equal( '/tmp/directory/file.txt' ); - expect( outputFileStub.calledOnce ).to.equal( true ); - expect( outputFileStub.firstCall.args[ 0 ] ).to.equal( '/tmp/file.txt' ); - expect( outputFileStub.firstCall.args[ 1 ] ).to.equal( 'Some data.' ); - } ); - } ); - } ); - - describe( 'clean', () => { - const files = [ - path.posix.join( 'test', 'foo', 'bar' ), - path.posix.join( 'test', 'bar', 'foo' ) - ]; - - let delArg; - - beforeEach( () => { - mockery.registerMock( 'del', globToDelete => { - delArg = globToDelete; - - return Promise.resolve( files ); - } ); - } ); - - it( 'removes files and informs about deletion using a logger', () => { - return tools.clean( 'test', '**' ) - .then( () => { - expect( delArg ).to.equal( path.posix.join( 'test', '**' ) ); - expect( loggerVerbosity ).to.equal( 'info' ); - expect( infoSpy.calledTwice ).to.equal( true ); - expect( infoSpy.firstCall.args[ 0 ] ).to.match( new RegExp( files[ 0 ] ) ); - expect( infoSpy.secondCall.args[ 0 ] ).to.match( new RegExp( files[ 1 ] ) ); - } ); - } ); - - it( 'works with paths that contain backslash', () => { - return tools.clean( 'test\\path', '**\\packages' ) - .then( () => { - expect( delArg ).to.equal( path.posix.join( 'test/path', '**/packages' ) ); - } ); - } ); - } ); } ); } ); diff --git a/packages/ckeditor5-dev-utils/tests/workspace.js b/packages/ckeditor5-dev-utils/tests/workspace.js deleted file mode 100644 index 0073deb5a..000000000 --- a/packages/ckeditor5-dev-utils/tests/workspace.js +++ /dev/null @@ -1,171 +0,0 @@ -/** - * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved. - * For licensing, see LICENSE.md. - */ - -'use strict'; - -const chai = require( 'chai' ); -const sinon = require( 'sinon' ); -const expect = chai.expect; -const path = require( 'path' ); -const ckeditor5Dirs = require( '../lib/workspace' ); -const tools = require( '../lib/tools' ); -const git = require( '../lib/git' ); -let sandbox; - -describe( 'utils', () => { - beforeEach( () => { - sandbox = sinon.createSandbox(); - } ); - - afterEach( () => { - sandbox.restore(); - } ); - - describe( 'ckeditor5dirs', () => { - describe( 'getDependencies', () => { - it( 'should be defined', () => expect( ckeditor5Dirs.getDependencies ).to.be.a( 'function' ) ); - - it( 'should return null if no CKEditor5 repository is found', () => { - const packageJSONDependencies = { - 'plugin1': '', - 'plugin2': '', - 'plugin3': '' - }; - expect( ckeditor5Dirs.getDependencies( packageJSONDependencies ) ).to.equal( null ); - expect( ckeditor5Dirs.getDependencies() ).to.equal( null ); - } ); - - it( 'should return only ckeditor5- dependencies', () => { - const packageJSONDependencies = { - 'plugin1': '', - 'ckeditor5-plugin-image': 'ckeditor/ckeditor5-plugin-image', - 'plugin2': '', - 'ckeditor5-core': 'ckeditor/ckeditor5-core' - }; - const ckeditorDependencies = ckeditor5Dirs.getDependencies( packageJSONDependencies ); - - expect( ckeditorDependencies ).to.be.an( 'object' ); - expect( ckeditorDependencies.plugin1 ).to.be.a( 'undefined' ); - expect( ckeditorDependencies.plugin2 ).to.be.a( 'undefined' ); - expect( ckeditorDependencies[ 'ckeditor5-plugin-image' ] ).to.be.a( 'string' ); - expect( ckeditorDependencies[ 'ckeditor5-core' ] ).to.be.a( 'string' ); - } ); - } ); - - describe( 'getDirectories', () => { - it( 'should be defined', () => expect( ckeditor5Dirs.getDirectories ).to.be.a( 'function' ) ); - - it( 'should return only ckeditor5 directories', () => { - const workspacePath = '/workspace/path'; - const sourceDirectories = [ 'tools', 'ckeditor5', 'ckeditor5-core', '.bin', 'ckeditor5-plugin-image' ]; - sandbox.stub( tools, 'getDirectories' ).returns( sourceDirectories ); - const directories = ckeditor5Dirs.getDirectories( workspacePath ); - - expect( directories.length ).to.equal( 2 ); - expect( directories[ 0 ] ).to.equal( 'ckeditor5-core' ); - expect( directories[ 1 ] ).to.equal( 'ckeditor5-plugin-image' ); - } ); - } ); - - describe( 'getSymlinks', () => { - it( 'should return CKE5 symlinks from provided path', () => { - const fs = require( 'fs' ); - const path = 'path/to/dir'; - sandbox.stub( fs, 'readdirSync' ).returns( [ - 'ckeditor5-core', - 'ckeditor5-image', - 'other-dependency' - ] ); - sandbox.stub( tools, 'isSymlink' ).returns( true ); - - const symlinks = ckeditor5Dirs.getSymlinks( path ); - expect( symlinks.length ).to.equal( 2 ); - expect( symlinks[ 0 ] ).to.equal( 'ckeditor5-core' ); - expect( symlinks[ 1 ] ).to.equal( 'ckeditor5-image' ); - } ); - } ); - - describe( 'getDevDirectories', () => { - const packageJSONDependencies = {}; - const workspacePath = '/workspace/path'; - const ckeditor5Path = path.posix.join( workspacePath, 'ckeditor5' ); - const dependencies = { - 'ckeditor5-plugin-image': 'ckeditor/ckeditor5-plugin-image', - 'ckeditor5-core': 'ckeditor/ckeditor5-core' - }; - const sourceDirectories = [ 'tools', 'ckeditor5', 'ckeditor5-core', '.bin', 'ckeditor5-plugin-image' ]; - const repositoryInfo = { name: 'ckeditor5-core' }; - - it( 'should be defined', () => expect( ckeditor5Dirs.getDevDirectories ).to.be.a( 'function' ) ); - - it( 'should return empty array if no dev directories were found - because of missing ckeditor5-* repos', () => { - const wrongRepositoryInfo = { name: 'plugins/plugin' }; - - sandbox.stub( ckeditor5Dirs, 'getDirectories' ).returns( sourceDirectories ); - sandbox.stub( ckeditor5Dirs, 'getDependencies' ).returns( dependencies ); - sandbox.stub( git, 'parseRepositoryUrl' ).returns( wrongRepositoryInfo ); - - const directories = ckeditor5Dirs.getDevDirectories( workspacePath, packageJSONDependencies, ckeditor5Path ); - - expect( directories ).to.be.a( 'array' ); - expect( directories.length ).to.equal( 0 ); - } ); - - it( 'should return empty array if no dev directories were found - because of missing ckeditor5-* dirs', () => { - const wrongDirectories = [ 'tools', 'ckeditor5', '.bin' ]; - - sandbox.stub( ckeditor5Dirs, 'getDirectories' ).returns( wrongDirectories ); - sandbox.stub( ckeditor5Dirs, 'getDependencies' ).returns( dependencies ); - sandbox.stub( git, 'parseRepositoryUrl' ).returns( repositoryInfo ); - - const directories = ckeditor5Dirs.getDevDirectories( workspacePath, packageJSONDependencies, ckeditor5Path ); - - expect( directories ).to.be.a( 'array' ); - expect( directories.length ).to.equal( 0 ); - } ); - - it( 'should return only ckeditor5 directories in development mode', () => { - sandbox.stub( ckeditor5Dirs, 'getDirectories' ).returns( sourceDirectories ); - sandbox.stub( ckeditor5Dirs, 'getDependencies' ).returns( dependencies ); - sandbox.stub( git, 'parseRepositoryUrl' ).returns( repositoryInfo ); - - const directories = ckeditor5Dirs.getDevDirectories( workspacePath, packageJSONDependencies, ckeditor5Path ); - - expect( directories.length ).to.equal( 2 ); - expect( directories[ 0 ] ).to.deep.equal( { - repositoryURL: 'ckeditor/ckeditor5-plugin-image', - repositoryPath: '/workspace/path/ckeditor5-plugin-image' - } ); - expect( directories[ 1 ] ).to.deep.equal( { - repositoryURL: 'ckeditor/ckeditor5-core', - repositoryPath: '/workspace/path/ckeditor5-core' - } ); - } ); - - it( 'should return only ckeditor5 directories in development mode, including root directory', () => { - sandbox.stub( ckeditor5Dirs, 'getDirectories' ).returns( sourceDirectories ); - sandbox.stub( ckeditor5Dirs, 'getDependencies' ).returns( dependencies ); - sandbox.stub( git, 'parseRepositoryUrl' ).returns( repositoryInfo ); - const includeRoot = true; - - const directories = ckeditor5Dirs.getDevDirectories( workspacePath, packageJSONDependencies, ckeditor5Path, includeRoot ); - - expect( directories.length ).to.equal( 3 ); - expect( directories[ 0 ] ).to.deep.equal( { - repositoryURL: 'ckeditor/ckeditor5', - repositoryPath: '/workspace/path/ckeditor5' - } ); - expect( directories[ 1 ] ).to.deep.equal( { - repositoryURL: 'ckeditor/ckeditor5-plugin-image', - repositoryPath: '/workspace/path/ckeditor5-plugin-image' - } ); - expect( directories[ 2 ] ).to.deep.equal( { - repositoryURL: 'ckeditor/ckeditor5-core', - repositoryPath: '/workspace/path/ckeditor5-core' - } ); - } ); - } ); - } ); -} ); From 616c669e80305945655a14391f682a3203014088 Mon Sep 17 00:00:00 2001 From: Kamil Piechaczek Date: Thu, 29 Aug 2024 21:24:10 +0200 Subject: [PATCH 2/8] Trying to get green CI. --- .../lib/builds/getdllpluginwebpackconfig.js | 2 +- .../tests/builds/getdllpluginwebpackconfig.js | 24 ++++++++----------- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/packages/ckeditor5-dev-utils/lib/builds/getdllpluginwebpackconfig.js b/packages/ckeditor5-dev-utils/lib/builds/getdllpluginwebpackconfig.js index 306b259b7..6df015019 100644 --- a/packages/ckeditor5-dev-utils/lib/builds/getdllpluginwebpackconfig.js +++ b/packages/ckeditor5-dev-utils/lib/builds/getdllpluginwebpackconfig.js @@ -32,7 +32,7 @@ module.exports = function getDllPluginWebpackConfig( webpack, options ) { // See: https://github.com/ckeditor/ckeditor5/issues/13136. const TerserPlugin = require( 'terser-webpack-plugin' ); - const { name: packageName } = require( path.join( options.packagePath, 'package.json' ) ); + const { name: packageName } = fs.readJsonSync( path.join( options.packagePath, 'package.json' ) ); const langDirExists = fs.existsSync( path.join( options.packagePath, 'lang' ) ); const indexJsExists = fs.existsSync( path.join( options.packagePath, 'src', 'index.js' ) ); diff --git a/packages/ckeditor5-dev-utils/tests/builds/getdllpluginwebpackconfig.js b/packages/ckeditor5-dev-utils/tests/builds/getdllpluginwebpackconfig.js index 303f379f3..7408203ba 100644 --- a/packages/ckeditor5-dev-utils/tests/builds/getdllpluginwebpackconfig.js +++ b/packages/ckeditor5-dev-utils/tests/builds/getdllpluginwebpackconfig.js @@ -13,7 +13,7 @@ const TerserPlugin = require( 'terser-webpack-plugin' ); const expect = chai.expect; describe( 'builds/getDllPluginWebpackConfig()', () => { - let sandbox, stubs, getDllPluginWebpackConfig, packageName; + let sandbox, stubs, getDllPluginWebpackConfig; const manifest = { content: { @@ -34,7 +34,8 @@ describe( 'builds/getDllPluginWebpackConfig()', () => { stubs = { fs: { - existsSync: sandbox.stub() + existsSync: sandbox.stub(), + readJsonSync: sandbox.stub() }, webpack: { BannerPlugin: sandbox.stub(), @@ -47,6 +48,10 @@ describe( 'builds/getDllPluginWebpackConfig()', () => { } }; + stubs.fs.readJsonSync.returns( { + name: '@ckeditor/ckeditor5-dev' + } ); + sandbox.stub( path, 'join' ).callsFake( ( ...args ) => args.join( '/' ) ); mockery.enable( { @@ -55,16 +60,9 @@ describe( 'builds/getDllPluginWebpackConfig()', () => { warnOnUnregistered: false } ); - packageName = '@ckeditor/ckeditor5-dev'; - mockery.registerMock( 'fs-extra', stubs.fs ); mockery.registerMock( '../loaders', stubs.loaders ); mockery.registerMock( '/manifest/path', manifest ); - mockery.registerMock( '/package/path/package.json', { - get name() { - return packageName; - } - } ); getDllPluginWebpackConfig = require( '../../lib/builds/getdllpluginwebpackconfig' ); } ); @@ -101,7 +99,9 @@ describe( 'builds/getDllPluginWebpackConfig()', () => { } ); it( 'transforms package with many dashes in its name', () => { - packageName = '@ckeditor/ckeditor5-html-embed'; + stubs.fs.readJsonSync.returns( { + name: '@ckeditor/ckeditor5-html-embed' + } ); const webpackConfig = getDllPluginWebpackConfig( stubs.webpack, { packagePath: '/package/path', @@ -231,10 +231,6 @@ describe( 'builds/getDllPluginWebpackConfig()', () => { } ); describe( '#loaders', () => { - beforeEach( () => { - packageName = '@ckeditor/ckeditor5-html-embed'; - } ); - describe( 'getTypeScriptLoader()', () => { it( 'it should use the default tsconfig.json if the "options.tsconfigPath" option is not specified', () => { getDllPluginWebpackConfig( stubs.webpack, { From 0553a59cfdb0b6144fb199f103ca1824cb499b1d Mon Sep 17 00:00:00 2001 From: Kamil Piechaczek Date: Thu, 29 Aug 2024 21:33:41 +0200 Subject: [PATCH 3/8] Do we need more RAM? --- .circleci/config.yml | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 52c63fca1..217678d71 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -57,7 +57,7 @@ commands: CKE5_GITHUB_REPOSITORY="ckeditor5-dev" CKE5_CIRCLE_APPROVAL_JOB_NAME="release_approval" CKE5_GITHUB_RELEASE_BRANCH="master" - + echo export CKE5_CIRCLE_APPROVAL_JOB_NAME=$CKE5_CIRCLE_APPROVAL_JOB_NAME >> $BASH_ENV echo export CKE5_GITHUB_RELEASE_BRANCH=$CKE5_GITHUB_RELEASE_BRANCH >> $BASH_ENV echo export CKE5_GITHUB_ORGANIZATION=$CKE5_GITHUB_ORGANIZATION >> $BASH_ENV @@ -96,6 +96,7 @@ jobs: validate_and_tests: machine: true + resource_class: large steps: - checkout - bootstrap_repository_command @@ -126,6 +127,7 @@ jobs: release_prepare: machine: true + resource_class: large steps: - checkout - bootstrap_repository_command @@ -135,6 +137,7 @@ jobs: trigger_release_process: machine: true + resource_class: large steps: - checkout - bootstrap_repository_command @@ -159,6 +162,7 @@ jobs: release_project: machine: true + resource_class: large steps: - checkout - bootstrap_repository_command @@ -166,10 +170,10 @@ jobs: name: Verify the trigger commit from the repository command: | #!/bin/bash - + CKE5_LATEST_COMMIT_HASH=$( git log -n 1 --pretty=format:%H origin/master ) CKE5_TRIGGER_COMMIT_HASH=<< pipeline.parameters.triggerCommitHash >> - + if [[ "${CKE5_LATEST_COMMIT_HASH}" != "${CKE5_TRIGGER_COMMIT_HASH}" ]]; then echo "There is a newer commit in the repository on the \`#master\` branch. Use its build to start the release." circleci-agent step halt @@ -180,13 +184,13 @@ jobs: name: Verify if a releaser triggered the job command: | #!/bin/bash - + # Do not fail if the Node script ends with non-zero exit code. set +e yarn ckeditor5-dev-ci-is-job-triggered-by-member EXIT_CODE=$( echo $? ) - + if [ ${EXIT_CODE} -ne 0 ]; then echo "Aborting the release due to failed verification of the approver (no rights to release)." From ac02ef882e11d9f0900243e4672da1d2b9beac60 Mon Sep 17 00:00:00 2001 From: Kamil Piechaczek Date: Fri, 30 Aug 2024 08:56:05 +0200 Subject: [PATCH 4/8] Checking a new script for runnig tests. --- .gitignore | 4 +- package.json | 29 +++-- .../ckeditor5-dev-build-tools/package.json | 1 + .../vitest.config.ts | 4 +- packages/ckeditor5-dev-bump-year/package.json | 8 +- packages/ckeditor5-dev-ci/package.json | 11 +- packages/ckeditor5-dev-docs/package.json | 10 +- .../tests/validators/fires-validator/index.js | 5 +- .../ckeditor5-dev-release-tools/package.json | 10 +- packages/ckeditor5-dev-stale-bot/package.json | 10 +- packages/ckeditor5-dev-tests/package.json | 14 +-- packages/ckeditor5-dev-transifex/package.json | 10 +- .../ckeditor5-dev-translations/package.json | 10 +- packages/ckeditor5-dev-utils/package.json | 11 +- packages/jsdoc-plugins/package.json | 4 + packages/typedoc-plugins/package.json | 10 +- scripts/runtest.js | 102 ++++++++++++++++++ 17 files changed, 198 insertions(+), 55 deletions(-) create mode 100644 scripts/runtest.js diff --git a/.gitignore b/.gitignore index 614cf45ad..6050712d8 100644 --- a/.gitignore +++ b/.gitignore @@ -4,8 +4,8 @@ .idea **/node_modules/** -.nyc_output/** -coverage/** +.nyc_output/ +coverage/ npm-debug.log yarn.lock executeinparallel-integration.log diff --git a/package.json b/package.json index a9c519eda..65685e08c 100644 --- a/package.json +++ b/package.json @@ -2,6 +2,17 @@ "name": "ckeditor5-dev", "version": "41.0.0", "private": true, + "author": "CKSource (http://cksource.com/)", + "license": "GPL-2.0-or-later", + "bugs": "https://github.com/ckeditor/ckeditor5-dev/issues", + "repository": { + "type": "git", + "url": "https://github.com/ckeditor/ckeditor5-dev.git" + }, + "homepage": "https://github.com/ckeditor/ckeditor5-dev#readme", + "engines": { + "node": ">=18.0.0" + }, "devDependencies": { "@ckeditor/ckeditor5-dev-ci": "^41.0.0", "@ckeditor/ckeditor5-dev-release-tools": "^41.0.0", @@ -12,27 +23,13 @@ "husky": "^8.0.2", "lint-staged": "^10.2.4", "listr2": "^6.5.0", - "mocha": "^7.1.2", "nyc": "^15.1.0", "semver": "^7.5.3" }, - "engines": { - "node": ">=18.0.0" - }, - "author": "CKSource (http://cksource.com/)", - "license": "GPL-2.0-or-later", - "bugs": "https://github.com/ckeditor/ckeditor5-dev/issues", - "repository": { - "type": "git", - "url": "https://github.com/ckeditor/ckeditor5-dev.git" - }, - "homepage": "https://github.com/ckeditor/ckeditor5-dev#readme", "scripts": { "postinstall": "node ./scripts/postinstall.js", - "test": "yarn run test:build-tools && yarn run test:js", - "test:build-tools": "yarn workspace @ckeditor/ckeditor5-dev-build-tools run test", - "test:js": "mocha 'packages/*/tests/**/*.js' --timeout 10000 --ignore 'packages/ckeditor5-dev-build-tools/**'", - "coverage": "nyc --reporter=lcov --reporter=text-summary yarn run test", + "test": "node ./scripts/runtest.js", + "coverage": "node ./scripts/runtest.js --coverage", "changelog": "node ./scripts/changelog.js", "release:prepare-packages": "node ./scripts/preparepackages.js", "release:publish-packages": "node ./scripts/publishpackages.js", diff --git a/packages/ckeditor5-dev-build-tools/package.json b/packages/ckeditor5-dev-build-tools/package.json index eca8d86ff..081472598 100644 --- a/packages/ckeditor5-dev-build-tools/package.json +++ b/packages/ckeditor5-dev-build-tools/package.json @@ -66,6 +66,7 @@ "build": "rollup -c rollup.config.js", "dev": "rollup -c rollup.config.js --watch", "test": "vitest run --config vitest.config.ts", + "coverage": "vitest run --config vitest.config.ts --coverage", "test:dev": "vitest dev" } } diff --git a/packages/ckeditor5-dev-build-tools/vitest.config.ts b/packages/ckeditor5-dev-build-tools/vitest.config.ts index 4b145fec8..1283f4cc2 100644 --- a/packages/ckeditor5-dev-build-tools/vitest.config.ts +++ b/packages/ckeditor5-dev-build-tools/vitest.config.ts @@ -10,11 +10,11 @@ export default defineConfig( { testTimeout: 10000, restoreMocks: true, coverage: { - enabled: true, provider: 'v8', include: [ 'src/**' - ] + ], + reporter: [ 'text', 'json', 'html', 'lcov' ] } } } ); diff --git a/packages/ckeditor5-dev-bump-year/package.json b/packages/ckeditor5-dev-bump-year/package.json index d903012c4..b2ef60364 100644 --- a/packages/ckeditor5-dev-bump-year/package.json +++ b/packages/ckeditor5-dev-bump-year/package.json @@ -4,14 +4,14 @@ "description": "Used to bump year in the licence text specified at the top of the file.", "keywords": [], "main": "lib/index.js", - "dependencies": { - "chalk": "^4.1.0", - "glob": "^10.2.5" - }, "engines": { "node": ">=18.0.0", "npm": ">=5.7.1" }, + "dependencies": { + "chalk": "^4.1.0", + "glob": "^10.2.5" + }, "files": [ "lib" ], diff --git a/packages/ckeditor5-dev-ci/package.json b/packages/ckeditor5-dev-ci/package.json index 4c459fd48..b525d9cb0 100644 --- a/packages/ckeditor5-dev-ci/package.json +++ b/packages/ckeditor5-dev-ci/package.json @@ -4,6 +4,10 @@ "description": "Utils used on various Continuous Integration services.", "keywords": [], "main": "lib/index.js", + "engines": { + "node": ">=18.0.0", + "npm": ">=5.7.1" + }, "dependencies": { "minimist": "^1.2.8", "node-fetch": "^2.6.7", @@ -12,12 +16,13 @@ "devDependencies": { "chai": "^4.2.0", "proxyquire": "^2.1.3", + "mocha": "^7.1.2", "mockery": "^2.1.0", "sinon": "^9.2.4" }, - "engines": { - "node": ">=18.0.0", - "npm": ">=5.7.1" + "scripts": { + "test": "mocha './tests/**/*.js' --timeout 10000", + "coverage": "nyc --reporter=lcov --reporter=text-summary yarn run test" }, "files": [ "bin", diff --git a/packages/ckeditor5-dev-docs/package.json b/packages/ckeditor5-dev-docs/package.json index 27735033a..742ddafbc 100644 --- a/packages/ckeditor5-dev-docs/package.json +++ b/packages/ckeditor5-dev-docs/package.json @@ -4,6 +4,10 @@ "description": "Tasks used to build and verify the documentation for CKEditor 5.", "keywords": [], "main": "lib/index.js", + "engines": { + "node": ">=18.0.0", + "npm": ">=5.7.1" + }, "dependencies": { "@ckeditor/ckeditor5-dev-utils": "^42.1.0", "@ckeditor/jsdoc-plugins": "^42.1.0", @@ -20,9 +24,9 @@ "proxyquire": "^2.1.3", "sinon": "^9.2.4" }, - "engines": { - "node": ">=18.0.0", - "npm": ">=5.7.1" + "scripts": { + "test": "mocha './tests/**/*.js' --timeout 10000", + "coverage": "nyc --reporter=lcov --reporter=text-summary yarn run test" }, "files": [ "lib" diff --git a/packages/ckeditor5-dev-docs/tests/validators/fires-validator/index.js b/packages/ckeditor5-dev-docs/tests/validators/fires-validator/index.js index 5cd4b8922..17f3428b1 100644 --- a/packages/ckeditor5-dev-docs/tests/validators/fires-validator/index.js +++ b/packages/ckeditor5-dev-docs/tests/validators/fires-validator/index.js @@ -3,11 +3,14 @@ * For licensing, see LICENSE.md. */ -const { expect } = require( 'chai' ); +const chai = require( 'chai' ); const sinon = require( 'sinon' ); const proxyquire = require( 'proxyquire' ); const testUtils = require( '../../utils' ); +const { expect } = chai; +chai.use( require( 'sinon-chai' ) ); + describe( 'dev-docs/validators/fires-validator', function() { this.timeout( 10 * 1000 ); diff --git a/packages/ckeditor5-dev-release-tools/package.json b/packages/ckeditor5-dev-release-tools/package.json index 4b84c2d8e..33aa35319 100644 --- a/packages/ckeditor5-dev-release-tools/package.json +++ b/packages/ckeditor5-dev-release-tools/package.json @@ -4,6 +4,10 @@ "description": "Tools used for releasing CKEditor 5 and related packages.", "keywords": [], "main": "lib/index.js", + "engines": { + "node": ">=18.0.0", + "npm": ">=5.7.1" + }, "dependencies": { "@ckeditor/ckeditor5-dev-utils": "^42.1.0", "@octokit/rest": "^19.0.0", @@ -37,9 +41,9 @@ "sinon": "^9.2.4", "strip-ansi": "^6.0.0" }, - "engines": { - "node": ">=18.0.0", - "npm": ">=5.7.1" + "scripts": { + "test": "mocha './tests/**/*.js' --timeout 10000", + "coverage": "nyc --reporter=lcov --reporter=text-summary yarn run test" }, "files": [ "lib" diff --git a/packages/ckeditor5-dev-stale-bot/package.json b/packages/ckeditor5-dev-stale-bot/package.json index 8c4203fe8..3fc40afd5 100644 --- a/packages/ckeditor5-dev-stale-bot/package.json +++ b/packages/ckeditor5-dev-stale-bot/package.json @@ -3,6 +3,10 @@ "version": "42.1.0", "description": "A stale bot is used to mark issues and pull requests that have not recently been updated.", "keywords": [], + "engines": { + "node": ">=18.0.0", + "npm": ">=5.7.1" + }, "dependencies": { "chalk": "^4.1.0", "date-fns": "^2.30.0", @@ -13,9 +17,9 @@ "upath": "^2.0.1" }, "devDependencies": {}, - "engines": { - "node": ">=18.0.0", - "npm": ">=5.7.1" + "scripts": { + "test": "mocha './tests/**/*.js' --timeout 10000", + "coverage": "nyc --reporter=lcov --reporter=text-summary yarn run test" }, "files": [ "bin", diff --git a/packages/ckeditor5-dev-tests/package.json b/packages/ckeditor5-dev-tests/package.json index ca0a9d6c3..826fefa2b 100644 --- a/packages/ckeditor5-dev-tests/package.json +++ b/packages/ckeditor5-dev-tests/package.json @@ -4,6 +4,10 @@ "description": "Testing environment for CKEditor 5.", "keywords": [], "main": "lib/index.js", + "engines": { + "node": ">=18.0.0", + "npm": ">=5.7.1" + }, "dependencies": { "@babel/core": "^7.10.5", "@ckeditor/ckeditor5-dev-translations": "^42.1.0", @@ -56,17 +60,15 @@ "mockery": "^2.1.0", "proxyquire": "^2.1.3" }, - "engines": { - "node": ">=18.0.0", - "npm": ">=5.7.1" + "scripts": { + "postinstall": "node bin/postinstall.js", + "test": "mocha './tests/**/*.js' --timeout 10000", + "coverage": "nyc --reporter=lcov --reporter=text-summary yarn run test" }, "files": [ "lib", "bin" ], - "scripts": { - "postinstall": "node bin/postinstall.js" - }, "bin": { "ckeditor5-dev-tests-run-automated": "bin/testautomated.js", "ckeditor5-dev-tests-run-manual": "bin/testmanual.js" diff --git a/packages/ckeditor5-dev-transifex/package.json b/packages/ckeditor5-dev-transifex/package.json index 5456c7042..ce37308ae 100644 --- a/packages/ckeditor5-dev-transifex/package.json +++ b/packages/ckeditor5-dev-transifex/package.json @@ -4,6 +4,10 @@ "description": "Used to download and upload translations using the Transifex service.", "keywords": [], "main": "lib/index.js", + "engines": { + "node": ">=18.0.0", + "npm": ">=5.7.1" + }, "dependencies": { "fs-extra": "^9.0.0", "del": "^5.1.0", @@ -21,9 +25,9 @@ "proxyquire": "^2.1.3", "sinon": "^9.2.4" }, - "engines": { - "node": ">=18.0.0", - "npm": ">=5.7.1" + "scripts": { + "test": "mocha './tests/**/*.js' --timeout 10000", + "coverage": "nyc --reporter=lcov --reporter=text-summary yarn run test" }, "files": [ "lib" diff --git a/packages/ckeditor5-dev-translations/package.json b/packages/ckeditor5-dev-translations/package.json index 78fc7952d..e5e70790a 100644 --- a/packages/ckeditor5-dev-translations/package.json +++ b/packages/ckeditor5-dev-translations/package.json @@ -4,6 +4,10 @@ "description": "CKEditor 5 translations plugin for webpack.", "keywords": [], "main": "lib/index.js", + "engines": { + "node": ">=18.0.0", + "npm": ">=5.7.1" + }, "dependencies": { "@babel/parser": "^7.18.9", "@babel/traverse": "^7.18.9", @@ -17,9 +21,9 @@ "proxyquire": "^2.1.3", "sinon": "^9.2.4" }, - "engines": { - "node": ">=18.0.0", - "npm": ">=5.7.1" + "scripts": { + "test": "mocha './tests/**/*.js' --timeout 10000", + "coverage": "nyc --reporter=lcov --reporter=text-summary yarn run test" }, "files": [ "lib" diff --git a/packages/ckeditor5-dev-utils/package.json b/packages/ckeditor5-dev-utils/package.json index aefa11aa6..3d8aef4c3 100644 --- a/packages/ckeditor5-dev-utils/package.json +++ b/packages/ckeditor5-dev-utils/package.json @@ -4,6 +4,10 @@ "description": "Utils for CKEditor 5 development tools packages.", "keywords": [], "main": "lib/index.js", + "engines": { + "node": ">=18.0.0", + "npm": ">=5.7.1" + }, "dependencies": { "@ckeditor/ckeditor5-dev-translations": "^42.1.0", "chalk": "^3.0.0", @@ -17,6 +21,7 @@ "is-interactive": "^1.0.0", "javascript-stringify": "^1.6.0", "mini-css-extract-plugin": "^2.4.2", + "mocha": "^7.1.2", "postcss": "^8.4.12", "postcss-import": "^14.1.0", "postcss-loader": "^4.3.0", @@ -34,9 +39,9 @@ "sinon": "^9.2.4", "vinyl": "^2.1.0" }, - "engines": { - "node": ">=18.0.0", - "npm": ">=5.7.1" + "scripts": { + "test": "mocha './tests/**/*.js' --timeout 10000", + "coverage": "nyc --reporter=lcov --reporter=text-summary yarn run test" }, "files": [ "lib" diff --git a/packages/jsdoc-plugins/package.json b/packages/jsdoc-plugins/package.json index 48b813ac9..d226561e3 100644 --- a/packages/jsdoc-plugins/package.json +++ b/packages/jsdoc-plugins/package.json @@ -23,6 +23,10 @@ "glob": "^10.2.5", "tmp": "^0.2.1" }, + "scripts": { + "test": "mocha './tests/**/*.js' --timeout 10000", + "coverage": "nyc --reporter=lcov --reporter=text-summary yarn run test" + }, "engines": { "node": ">=18.0.0", "npm": ">=5.7.1" diff --git a/packages/typedoc-plugins/package.json b/packages/typedoc-plugins/package.json index 988ff88c8..2b91e8e84 100644 --- a/packages/typedoc-plugins/package.json +++ b/packages/typedoc-plugins/package.json @@ -4,6 +4,10 @@ "description": "Various TypeDoc plugins developed by the CKEditor 5 team.", "keywords": [], "main": "lib/index.js", + "engines": { + "node": ">=18.0.0", + "npm": ">=5.7.1" + }, "devDependencies": { "chai": "^4.2.0", "fast-glob": "^3.2.4", @@ -12,9 +16,9 @@ "peerDependencies": { "typedoc": "^0.23.15" }, - "engines": { - "node": ">=18.0.0", - "npm": ">=5.7.1" + "scripts": { + "test": "mocha './tests/**/*.js' --timeout 10000", + "coverage": "nyc --reporter=lcov --reporter=text-summary yarn run test" }, "files": [ "lib" diff --git a/scripts/runtest.js b/scripts/runtest.js new file mode 100644 index 000000000..9a17c4122 --- /dev/null +++ b/scripts/runtest.js @@ -0,0 +1,102 @@ +#!/usr/bin/env node + +/** + * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved. + * For licensing, see LICENSE.md. + */ + +/* eslint-env node */ + +'use strict'; + +const path = require( 'path' ); +const { execSync } = require( 'child_process' ); +const fs = require( 'fs-extra' ); +const { globSync } = require( 'glob' ); +const minimist = require( 'minimist' ); +const chalk = require( 'chalk' ); + +main(); + +function main() { + let hasError = false; + const cwd = process.cwd(); + const coverageFile = path.join( cwd, 'coverage', 'lcov.info' ); + const { coverage } = parseArguments( process.argv.slice( 2 ) ); + + const packages = globSync( './packages/*/package.json' ) + .map( packageJsonPath => ( { + relativePath: path.join( packageJsonPath, '..' ), + packageJson: fs.readJsonSync( packageJsonPath ) + } ) ) + .reverse(); + + const testablePackages = packages.filter( item => isTestable( item.packageJson ) ); + const ignoredPackages = packages.filter( item => !testablePackages.find( testable => item.relativePath === testable.relativePath ) ); + + for ( const { relativePath, packageJson } of testablePackages ) { + console.log( chalk.bold.magenta( `\nRunning tests for "${ chalk.underline( packageJson.name ) }"...` ) ); + const testScript = coverage ? 'coverage' : 'test'; + + try { + execSync( `npm run ${ testScript } --silent`, { + stdio: 'inherit', + cwd: path.join( cwd, relativePath ) + } ); + } catch ( error ) { + hasError = true; + } + } + + if ( coverage ) { + fs.emptyDir( path.join( coverageFile, '..' ) ); + + // Merge separate reports into a single file that would be sent to Coveralls. + for ( const lcovPath of globSync( './packages/*/coverage/lcov.info' ) ) { + const relativePackagePath = path.join( lcovPath, '..', '..' ); + const content = fs.readFileSync( lcovPath, 'utf-8' ) + .replaceAll( /^(SF:)/gm, `$1${ relativePackagePath }/` ); + + fs.writeFileSync( coverageFile, content, { flag: 'as' } ); + } + } + + if ( ignoredPackages.length ) { + console.log( chalk.yellow( '\nThe following packages do not define tests:' ) ); + + ignoredPackages.forEach( ( { packageJson } ) => { + console.log( ` - ${ packageJson.name }` ); + } ); + } + + if ( hasError ) { + process.exit( 1 ); + } +} + +/** + * @param {Object} packageJson + * @returns {Boolean} + */ +function isTestable( packageJson ) { + return !!packageJson?.scripts?.test; +} + +/** + * @param {Array.} args + * @returns {Object} result + * @returns {Boolean} result.coverage + */ +function parseArguments( args ) { + const config = { + boolean: [ + 'coverage' + ], + + default: { + coverage: false + } + }; + + return minimist( args, config ); +} From 40d42a89a166b0f22668e34c8325641b34476707 Mon Sep 17 00:00:00 2001 From: Kamil Piechaczek Date: Fri, 30 Aug 2024 09:44:08 +0200 Subject: [PATCH 5/8] Ensure the coverage file exists. --- scripts/runtest.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/runtest.js b/scripts/runtest.js index 9a17c4122..7bf015532 100644 --- a/scripts/runtest.js +++ b/scripts/runtest.js @@ -49,7 +49,8 @@ function main() { } if ( coverage ) { - fs.emptyDir( path.join( coverageFile, '..' ) ); + fs.emptyDirSync( path.join( coverageFile, '..' ) ); + fs.ensureFileSync( path.join( coverageFile ) ); // Merge separate reports into a single file that would be sent to Coveralls. for ( const lcovPath of globSync( './packages/*/coverage/lcov.info' ) ) { From 81fb6bca50055700890b0366d2b6a27a658eac09 Mon Sep 17 00:00:00 2001 From: Kamil Piechaczek Date: Fri, 30 Aug 2024 10:59:23 +0200 Subject: [PATCH 6/8] Deps clean up. --- package.json | 14 +++-- .../ckeditor5-dev-build-tools/package.json | 12 ++++- packages/ckeditor5-dev-bump-year/package.json | 24 ++++----- packages/ckeditor5-dev-ci/package.json | 51 ++++++++++--------- .../lib/checkdependencies.js | 4 +- .../package.json | 30 +++++------ packages/ckeditor5-dev-docs/package.json | 34 +++++++------ .../ckeditor5-dev-release-tools/package.json | 35 ++++++------- packages/ckeditor5-dev-stale-bot/package.json | 45 +++++++++------- packages/ckeditor5-dev-tests/package.json | 50 +++++++++++------- packages/ckeditor5-dev-transifex/package.json | 28 +++++----- .../ckeditor5-dev-translations/package.json | 26 +++++----- packages/ckeditor5-dev-utils/package.json | 39 ++++++++------ .../ckeditor5-dev-web-crawler/package.json | 28 +++++----- packages/jsdoc-plugins/package.json | 42 +++++++-------- packages/typedoc-plugins/package.json | 30 ++++++----- scripts/bump-year.js | 2 +- scripts/changelog.js | 2 +- 18 files changed, 272 insertions(+), 224 deletions(-) diff --git a/package.json b/package.json index 65685e08c..3f0d18af8 100644 --- a/package.json +++ b/package.json @@ -1,10 +1,10 @@ { "name": "ckeditor5-dev", - "version": "41.0.0", + "version": "42.1.0", "private": true, "author": "CKSource (http://cksource.com/)", "license": "GPL-2.0-or-later", - "bugs": "https://github.com/ckeditor/ckeditor5-dev/issues", + "bugs": "https://github.com/ckeditor/ckeditor5/issues", "repository": { "type": "git", "url": "https://github.com/ckeditor/ckeditor5-dev.git" @@ -14,17 +14,21 @@ "node": ">=18.0.0" }, "devDependencies": { - "@ckeditor/ckeditor5-dev-ci": "^41.0.0", - "@ckeditor/ckeditor5-dev-release-tools": "^41.0.0", + "@ckeditor/ckeditor5-dev-ci": "^42.1.0", + "@ckeditor/ckeditor5-dev-release-tools": "^42.1.0", + "@ckeditor/ckeditor5-dev-bump-year": "^42.1.0", "coveralls": "^3.1.1", "eslint": "^7.0.0", "eslint-config-ckeditor5": "^6.0.0", + "fs-extra": "^11.2.0", "glob": "^10.2.5", "husky": "^8.0.2", "lint-staged": "^10.2.4", "listr2": "^6.5.0", + "minimist": "^1.2.8", "nyc": "^15.1.0", - "semver": "^7.5.3" + "semver": "^7.5.3", + "upath": "^2.0.1" }, "scripts": { "postinstall": "node ./scripts/postinstall.js", diff --git a/packages/ckeditor5-dev-build-tools/package.json b/packages/ckeditor5-dev-build-tools/package.json index 081472598..82a8b5cdd 100644 --- a/packages/ckeditor5-dev-build-tools/package.json +++ b/packages/ckeditor5-dev-build-tools/package.json @@ -27,7 +27,6 @@ "ckeditor5-dev-build-tools": "bin/build-project.js" }, "dependencies": { - "@fullhuman/postcss-purgecss": "^6.0.0", "@rollup/plugin-commonjs": "^25.0.7", "@rollup/plugin-json": "^6.1.0", "@rollup/plugin-node-resolve": "^15.2.3", @@ -44,12 +43,15 @@ "lodash-es": "^4.17.21", "magic-string": "^0.30.6", "pofile": "^1.1.4", + "postcss": "^8.0.0", "postcss-mixins": "^9.0.4", "postcss-nesting": "^12.0.2", + "purgecss": "^6.0.0", "rollup": "^4.9.5", "rollup-plugin-styles": "^4.0.0", "rollup-plugin-svg-import": "^3.0.0", "source-map": "^0.7.4", + "source-map-js": "^1.2.0", "upath": "^2.0.1" }, "devDependencies": { @@ -68,5 +70,11 @@ "test": "vitest run --config vitest.config.ts", "coverage": "vitest run --config vitest.config.ts --coverage", "test:dev": "vitest dev" - } + }, + "depcheckIgnore": [ + "@types/css", + "@vitest/coverage-v8", + "estree", + "typescript" + ] } diff --git a/packages/ckeditor5-dev-bump-year/package.json b/packages/ckeditor5-dev-bump-year/package.json index b2ef60364..1ce7766fe 100644 --- a/packages/ckeditor5-dev-bump-year/package.json +++ b/packages/ckeditor5-dev-bump-year/package.json @@ -3,18 +3,6 @@ "version": "42.1.0", "description": "Used to bump year in the licence text specified at the top of the file.", "keywords": [], - "main": "lib/index.js", - "engines": { - "node": ">=18.0.0", - "npm": ">=5.7.1" - }, - "dependencies": { - "chalk": "^4.1.0", - "glob": "^10.2.5" - }, - "files": [ - "lib" - ], "author": "CKSource (http://cksource.com/)", "license": "GPL-2.0-or-later", "homepage": "https://github.com/ckeditor/ckeditor5-dev/tree/master/packages/ckeditor5-dev-bump-year", @@ -23,5 +11,17 @@ "type": "git", "url": "https://github.com/ckeditor/ckeditor5-dev.git", "directory": "packages/ckeditor5-dev-bump-year" + }, + "engines": { + "node": ">=18.0.0", + "npm": ">=5.7.1" + }, + "main": "lib/index.js", + "files": [ + "lib" + ], + "dependencies": { + "chalk": "^4.1.0", + "glob": "^10.2.5" } } diff --git a/packages/ckeditor5-dev-ci/package.json b/packages/ckeditor5-dev-ci/package.json index b525d9cb0..c53e8de4f 100644 --- a/packages/ckeditor5-dev-ci/package.json +++ b/packages/ckeditor5-dev-ci/package.json @@ -3,27 +3,20 @@ "version": "42.1.0", "description": "Utils used on various Continuous Integration services.", "keywords": [], - "main": "lib/index.js", + "author": "CKSource (http://cksource.com/)", + "license": "GPL-2.0-or-later", + "homepage": "https://github.com/ckeditor/ckeditor5-dev/tree/master/packages/ckeditor5-dev-ci", + "bugs": "https://github.com/ckeditor/ckeditor5/issues", + "repository": { + "type": "git", + "url": "https://github.com/ckeditor/ckeditor5-dev.git", + "directory": "packages/ckeditor5-dev-ci" + }, "engines": { "node": ">=18.0.0", "npm": ">=5.7.1" }, - "dependencies": { - "minimist": "^1.2.8", - "node-fetch": "^2.6.7", - "slack-notify": "^2.0.6" - }, - "devDependencies": { - "chai": "^4.2.0", - "proxyquire": "^2.1.3", - "mocha": "^7.1.2", - "mockery": "^2.1.0", - "sinon": "^9.2.4" - }, - "scripts": { - "test": "mocha './tests/**/*.js' --timeout 10000", - "coverage": "nyc --reporter=lcov --reporter=text-summary yarn run test" - }, + "main": "lib/index.js", "files": [ "bin", "lib" @@ -39,13 +32,21 @@ "ckeditor5-dev-ci-circle-disable-auto-cancel-builds": "bin/circle-disable-auto-cancel-builds.js", "ckeditor5-dev-ci-circle-enable-auto-cancel-builds": "bin/circle-enable-auto-cancel-builds.js" }, - "author": "CKSource (http://cksource.com/)", - "license": "GPL-2.0-or-later", - "homepage": "https://github.com/ckeditor/ckeditor5-dev/tree/master/packages/ckeditor5-dev-ci", - "bugs": "https://github.com/ckeditor/ckeditor5/issues", - "repository": { - "type": "git", - "url": "https://github.com/ckeditor/ckeditor5-dev.git", - "directory": "packages/ckeditor5-dev-ci" + "dependencies": { + "@octokit/rest": "^19.0.0", + "minimist": "^1.2.8", + "node-fetch": "^2.6.7", + "slack-notify": "^2.0.6" + }, + "devDependencies": { + "chai": "^4.2.0", + "proxyquire": "^2.1.3", + "mocha": "^7.1.2", + "mockery": "^2.1.0", + "sinon": "^9.2.4" + }, + "scripts": { + "test": "mocha './tests/**/*.js' --timeout 10000", + "coverage": "nyc --reporter=lcov --reporter=text-summary yarn run test" } } diff --git a/packages/ckeditor5-dev-dependency-checker/lib/checkdependencies.js b/packages/ckeditor5-dev-dependency-checker/lib/checkdependencies.js index 53477c4a0..810a16141 100644 --- a/packages/ckeditor5-dev-dependency-checker/lib/checkdependencies.js +++ b/packages/ckeditor5-dev-dependency-checker/lib/checkdependencies.js @@ -6,7 +6,7 @@ 'use strict'; const fs = require( 'fs' ); -const upath = require( 'path' ); +const upath = require( 'upath' ); const { globSync } = require( 'glob' ); const depCheck = require( 'depcheck' ); const chalk = require( 'chalk' ); @@ -390,7 +390,9 @@ async function isDevDependency( packageName, absolutePaths ) { /** * These folders contain the source code of the packages. */ + /[/\\]bin[/\\]/, /[/\\]src[/\\]/, + /[/\\]lib[/\\]/, /[/\\]theme[/\\]/, /** diff --git a/packages/ckeditor5-dev-dependency-checker/package.json b/packages/ckeditor5-dev-dependency-checker/package.json index 8a3f3dd6d..d92a9b014 100644 --- a/packages/ckeditor5-dev-dependency-checker/package.json +++ b/packages/ckeditor5-dev-dependency-checker/package.json @@ -3,13 +3,14 @@ "version": "42.1.0", "description": "Contains tools for validating dependencies specified in package.json.", "keywords": [], - "dependencies": { - "@ckeditor/ckeditor5-dev-utils": "^42.1.0", - "chalk": "^4.1.0", - "depcheck": "^1.3.1", - "glob": "^10.2.5", - "minimist": "^1.2.8", - "upath": "^2.0.1" + "author": "CKSource (http://cksource.com/)", + "license": "GPL-2.0-or-later", + "homepage": "https://github.com/ckeditor/ckeditor5-dev/tree/master/packages/ckeditor5-dev-dependency-checker", + "bugs": "https://github.com/ckeditor/ckeditor5/issues", + "repository": { + "type": "git", + "url": "https://github.com/ckeditor/ckeditor5-dev.git", + "directory": "packages/ckeditor5-dev-dependency-checker" }, "engines": { "node": ">=18.0.0", @@ -22,13 +23,12 @@ "bin": { "ckeditor5-dev-dependency-checker": "bin/dependencychecker.js" }, - "author": "CKSource (http://cksource.com/)", - "license": "GPL-2.0-or-later", - "homepage": "https://github.com/ckeditor/ckeditor5-dev/tree/master/packages/ckeditor5-dev-dependency-checker", - "bugs": "https://github.com/ckeditor/ckeditor5/issues", - "repository": { - "type": "git", - "url": "https://github.com/ckeditor/ckeditor5-dev.git", - "directory": "packages/ckeditor5-dev-dependency-checker" + "dependencies": { + "@ckeditor/ckeditor5-dev-utils": "^42.1.0", + "chalk": "^4.1.0", + "depcheck": "^1.3.1", + "glob": "^10.2.5", + "minimist": "^1.2.8", + "upath": "^2.0.1" } } diff --git a/packages/ckeditor5-dev-docs/package.json b/packages/ckeditor5-dev-docs/package.json index 742ddafbc..bd6cd2196 100644 --- a/packages/ckeditor5-dev-docs/package.json +++ b/packages/ckeditor5-dev-docs/package.json @@ -3,17 +3,29 @@ "version": "42.1.0", "description": "Tasks used to build and verify the documentation for CKEditor 5.", "keywords": [], - "main": "lib/index.js", + "author": "CKSource (http://cksource.com/)", + "license": "GPL-2.0-or-later", + "homepage": "https://github.com/ckeditor/ckeditor5-dev/tree/master/packages/ckeditor5-dev-docs", + "bugs": "https://github.com/ckeditor/ckeditor5/issues", + "repository": { + "type": "git", + "url": "https://github.com/ckeditor/ckeditor5-dev.git", + "directory": "packages/ckeditor5-dev-docs" + }, "engines": { "node": ">=18.0.0", "npm": ">=5.7.1" }, + "main": "lib/index.js", + "files": [ + "lib" + ], "dependencies": { "@ckeditor/ckeditor5-dev-utils": "^42.1.0", "@ckeditor/jsdoc-plugins": "^42.1.0", "@ckeditor/typedoc-plugins": "^42.1.0", "fast-glob": "^3.2.4", - "fs-extra": "^9.0.0", + "fs-extra": "^11.2.0", "jsdoc": "ckeditor/jsdoc#fixed-trailing-comment-doclets", "tmp": "^0.2.1", "typedoc": "^0.23.15", @@ -22,22 +34,14 @@ "devDependencies": { "chai": "^4.2.0", "proxyquire": "^2.1.3", - "sinon": "^9.2.4" + "sinon": "^9.2.4", + "sinon-chai": "^3.7.0" }, "scripts": { "test": "mocha './tests/**/*.js' --timeout 10000", "coverage": "nyc --reporter=lcov --reporter=text-summary yarn run test" }, - "files": [ - "lib" - ], - "author": "CKSource (http://cksource.com/)", - "license": "GPL-2.0-or-later", - "homepage": "https://github.com/ckeditor/ckeditor5-dev/tree/master/packages/ckeditor5-dev-docs", - "bugs": "https://github.com/ckeditor/ckeditor5/issues", - "repository": { - "type": "git", - "url": "https://github.com/ckeditor/ckeditor5-dev.git", - "directory": "packages/ckeditor5-dev-docs" - } + "depcheckIgnore": [ + "typedoc-plugin-rename-defaults" + ] } diff --git a/packages/ckeditor5-dev-release-tools/package.json b/packages/ckeditor5-dev-release-tools/package.json index 33aa35319..14479edff 100644 --- a/packages/ckeditor5-dev-release-tools/package.json +++ b/packages/ckeditor5-dev-release-tools/package.json @@ -3,16 +3,27 @@ "version": "42.1.0", "description": "Tools used for releasing CKEditor 5 and related packages.", "keywords": [], - "main": "lib/index.js", + "author": "CKSource (http://cksource.com/)", + "license": "GPL-2.0-or-later", + "homepage": "https://github.com/ckeditor/ckeditor5-dev/tree/master/packages/ckeditor5-dev-release-tools", + "bugs": "https://github.com/ckeditor/ckeditor5/issues", + "repository": { + "type": "git", + "url": "https://github.com/ckeditor/ckeditor5-dev.git", + "directory": "packages/ckeditor5-dev-release-tools" + }, "engines": { "node": ">=18.0.0", "npm": ">=5.7.1" }, + "main": "lib/index.js", + "files": [ + "lib" + ], "dependencies": { "@ckeditor/ckeditor5-dev-utils": "^42.1.0", "@octokit/rest": "^19.0.0", "chalk": "^4.0.0", - "cli-table": "^0.3.1", "cli-columns": "^4.0.0", "compare-func": "^2.0.0", "concat-stream": "^2.0.0", @@ -20,15 +31,12 @@ "conventional-commits-filter": "^3.0.0", "conventional-commits-parser": "^4.0.0", "date-fns": "^2.30.0", - "diff": "^5.0.0", - "fs-extra": "^9.1.0", + "fs-extra": "^11.2.0", "git-raw-commits": "^3.0.0", "glob": "^10.2.5", "inquirer": "^7.1.0", "lodash": "^4.17.15", "minimatch": "^3.0.4", - "mkdirp": "^1.0.4", - "parse-github-url": "^1.0.2", "semver": "^7.5.3", "upath": "^2.0.1" }, @@ -38,23 +46,10 @@ "mockery": "^2.1.0", "mock-fs": "^5.1.2", "proxyquire": "^2.1.3", - "sinon": "^9.2.4", - "strip-ansi": "^6.0.0" + "sinon": "^9.2.4" }, "scripts": { "test": "mocha './tests/**/*.js' --timeout 10000", "coverage": "nyc --reporter=lcov --reporter=text-summary yarn run test" - }, - "files": [ - "lib" - ], - "author": "CKSource (http://cksource.com/)", - "license": "GPL-2.0-or-later", - "homepage": "https://github.com/ckeditor/ckeditor5-dev/tree/master/packages/ckeditor5-dev-release-tools", - "bugs": "https://github.com/ckeditor/ckeditor5/issues", - "repository": { - "type": "git", - "url": "https://github.com/ckeditor/ckeditor5-dev.git", - "directory": "packages/ckeditor5-dev-release-tools" } } diff --git a/packages/ckeditor5-dev-stale-bot/package.json b/packages/ckeditor5-dev-stale-bot/package.json index 3fc40afd5..a4e493e83 100644 --- a/packages/ckeditor5-dev-stale-bot/package.json +++ b/packages/ckeditor5-dev-stale-bot/package.json @@ -3,38 +3,47 @@ "version": "42.1.0", "description": "A stale bot is used to mark issues and pull requests that have not recently been updated.", "keywords": [], + "author": "CKSource (http://cksource.com/)", + "license": "GPL-2.0-or-later", + "homepage": "https://github.com/ckeditor/ckeditor5-dev/tree/master/packages/ckeditor5-dev-stale-bot", + "bugs": "https://github.com/ckeditor/ckeditor5/issues", + "repository": { + "type": "git", + "url": "https://github.com/ckeditor/ckeditor5-dev.git", + "directory": "packages/ckeditor5-dev-stale-bot" + }, "engines": { "node": ">=18.0.0", "npm": ">=5.7.1" }, + "files": [ + "bin", + "lib" + ], + "bin": { + "ckeditor5-dev-stale-bot": "bin/stale-bot.js" + }, "dependencies": { + "@ckeditor/ckeditor5-dev-utils": "^42.1.0", "chalk": "^4.1.0", "date-fns": "^2.30.0", - "fs-extra": "^11.1.1", + "fs-extra": "^11.2.0", "graphql": "^16.8.1", "graphql-request": "^6.1.0", + "minimist": "^1.2.8", "ora": "^5.2.0", "upath": "^2.0.1" }, - "devDependencies": {}, + "devDependencies": { + "chai": "^4.2.0", + "sinon": "^9.2.4", + "proxyquire": "^2.1.3" + }, "scripts": { "test": "mocha './tests/**/*.js' --timeout 10000", "coverage": "nyc --reporter=lcov --reporter=text-summary yarn run test" }, - "files": [ - "bin", - "lib" - ], - "bin": { - "ckeditor5-dev-stale-bot": "bin/stale-bot.js" - }, - "author": "CKSource (http://cksource.com/)", - "license": "GPL-2.0-or-later", - "homepage": "https://github.com/ckeditor/ckeditor5-dev/tree/master/packages/ckeditor5-dev-stale-bot", - "bugs": "https://github.com/ckeditor/ckeditor5/issues", - "repository": { - "type": "git", - "url": "https://github.com/ckeditor/ckeditor5-dev.git", - "directory": "packages/ckeditor5-dev-stale-bot" - } + "depcheckIgnore": [ + "graphql" + ] } diff --git a/packages/ckeditor5-dev-tests/package.json b/packages/ckeditor5-dev-tests/package.json index 826fefa2b..d3056c531 100644 --- a/packages/ckeditor5-dev-tests/package.json +++ b/packages/ckeditor5-dev-tests/package.json @@ -3,11 +3,28 @@ "version": "42.1.0", "description": "Testing environment for CKEditor 5.", "keywords": [], - "main": "lib/index.js", + "author": "CKSource (http://cksource.com/)", + "license": "GPL-2.0-or-later", + "homepage": "https://github.com/ckeditor/ckeditor5-dev/tree/master/packages/ckeditor5-dev-tests", + "bugs": "https://github.com/ckeditor/ckeditor5/issues", + "repository": { + "type": "git", + "url": "https://github.com/ckeditor/ckeditor5-dev.git", + "directory": "packages/ckeditor5-dev-tests" + }, "engines": { "node": ">=18.0.0", "npm": ">=5.7.1" }, + "main": "lib/index.js", + "files": [ + "lib", + "bin" + ], + "bin": { + "ckeditor5-dev-tests-run-automated": "bin/testautomated.js", + "ckeditor5-dev-tests-run-manual": "bin/testmanual.js" + }, "dependencies": { "@babel/core": "^7.10.5", "@ckeditor/ckeditor5-dev-translations": "^42.1.0", @@ -26,7 +43,7 @@ "commonmark": "^0.29.1", "del": "^5.1.0", "dom-combiner": "^0.1.3", - "fs-extra": "^9.0.0", + "fs-extra": "^11.2.0", "glob": "^10.2.5", "inquirer": "^7.1.0", "is-interactive": "^1.0.0", @@ -60,26 +77,21 @@ "mockery": "^2.1.0", "proxyquire": "^2.1.3" }, + "depcheckIgnore": [ + "@babel/core", + "@types/chai", + "@types/karma-sinon-chai", + "@types/mocha", + "@types/sinon", + "babel-plugin-istanbul", + "buffer", + "mocha", + "process", + "typescript" + ], "scripts": { "postinstall": "node bin/postinstall.js", "test": "mocha './tests/**/*.js' --timeout 10000", "coverage": "nyc --reporter=lcov --reporter=text-summary yarn run test" - }, - "files": [ - "lib", - "bin" - ], - "bin": { - "ckeditor5-dev-tests-run-automated": "bin/testautomated.js", - "ckeditor5-dev-tests-run-manual": "bin/testmanual.js" - }, - "author": "CKSource (http://cksource.com/)", - "license": "GPL-2.0-or-later", - "homepage": "https://github.com/ckeditor/ckeditor5-dev/tree/master/packages/ckeditor5-dev-tests", - "bugs": "https://github.com/ckeditor/ckeditor5/issues", - "repository": { - "type": "git", - "url": "https://github.com/ckeditor/ckeditor5-dev.git", - "directory": "packages/ckeditor5-dev-tests" } } diff --git a/packages/ckeditor5-dev-transifex/package.json b/packages/ckeditor5-dev-transifex/package.json index ce37308ae..edc0efcd5 100644 --- a/packages/ckeditor5-dev-transifex/package.json +++ b/packages/ckeditor5-dev-transifex/package.json @@ -3,13 +3,25 @@ "version": "42.1.0", "description": "Used to download and upload translations using the Transifex service.", "keywords": [], - "main": "lib/index.js", + "author": "CKSource (http://cksource.com/)", + "license": "GPL-2.0-or-later", + "homepage": "https://github.com/ckeditor/ckeditor5-dev/tree/master/packages/ckeditor5-dev-transifex", + "bugs": "https://github.com/ckeditor/ckeditor5/issues", + "repository": { + "type": "git", + "url": "https://github.com/ckeditor/ckeditor5-dev.git", + "directory": "packages/ckeditor5-dev-transifex" + }, "engines": { "node": ">=18.0.0", "npm": ">=5.7.1" }, + "main": "lib/index.js", + "files": [ + "lib" + ], "dependencies": { - "fs-extra": "^9.0.0", + "fs-extra": "^11.2.0", "del": "^5.1.0", "@ckeditor/ckeditor5-dev-utils": "^42.1.0", "@ckeditor/ckeditor5-dev-translations": "^42.1.0", @@ -28,17 +40,5 @@ "scripts": { "test": "mocha './tests/**/*.js' --timeout 10000", "coverage": "nyc --reporter=lcov --reporter=text-summary yarn run test" - }, - "files": [ - "lib" - ], - "author": "CKSource (http://cksource.com/)", - "license": "GPL-2.0-or-later", - "homepage": "https://github.com/ckeditor/ckeditor5-dev/tree/master/packages/ckeditor5-dev-transifex", - "bugs": "https://github.com/ckeditor/ckeditor5/issues", - "repository": { - "type": "git", - "url": "https://github.com/ckeditor/ckeditor5-dev.git", - "directory": "packages/ckeditor5-dev-transifex" } } diff --git a/packages/ckeditor5-dev-translations/package.json b/packages/ckeditor5-dev-translations/package.json index e5e70790a..120900726 100644 --- a/packages/ckeditor5-dev-translations/package.json +++ b/packages/ckeditor5-dev-translations/package.json @@ -3,11 +3,23 @@ "version": "42.1.0", "description": "CKEditor 5 translations plugin for webpack.", "keywords": [], - "main": "lib/index.js", + "author": "CKSource (http://cksource.com/)", + "license": "GPL-2.0-or-later", + "homepage": "https://github.com/ckeditor/ckeditor5-dev/tree/master/packages/ckeditor5-dev-translations", + "bugs": "https://github.com/ckeditor/ckeditor5/issues", + "repository": { + "type": "git", + "url": "https://github.com/ckeditor/ckeditor5-dev.git", + "directory": "packages/ckeditor5-dev-translations" + }, "engines": { "node": ">=18.0.0", "npm": ">=5.7.1" }, + "main": "lib/index.js", + "files": [ + "lib" + ], "dependencies": { "@babel/parser": "^7.18.9", "@babel/traverse": "^7.18.9", @@ -24,17 +36,5 @@ "scripts": { "test": "mocha './tests/**/*.js' --timeout 10000", "coverage": "nyc --reporter=lcov --reporter=text-summary yarn run test" - }, - "files": [ - "lib" - ], - "author": "CKSource (http://cksource.com/)", - "license": "GPL-2.0-or-later", - "homepage": "https://github.com/ckeditor/ckeditor5-dev/tree/master/packages/ckeditor5-dev-translations", - "bugs": "https://github.com/ckeditor/ckeditor5/issues", - "repository": { - "type": "git", - "url": "https://github.com/ckeditor/ckeditor5-dev.git", - "directory": "packages/ckeditor5-dev-translations" } } diff --git a/packages/ckeditor5-dev-utils/package.json b/packages/ckeditor5-dev-utils/package.json index 3d8aef4c3..504048951 100644 --- a/packages/ckeditor5-dev-utils/package.json +++ b/packages/ckeditor5-dev-utils/package.json @@ -3,11 +3,23 @@ "version": "42.1.0", "description": "Utils for CKEditor 5 development tools packages.", "keywords": [], - "main": "lib/index.js", + "author": "CKSource (http://cksource.com/)", + "license": "GPL-2.0-or-later", + "homepage": "https://github.com/ckeditor/ckeditor5-dev/tree/master/packages/ckeditor5-dev-utils", + "bugs": "https://github.com/ckeditor/ckeditor5/issues", + "repository": { + "type": "git", + "url": "https://github.com/ckeditor/ckeditor5-dev.git", + "directory": "packages/ckeditor5-dev-utils" + }, "engines": { "node": ">=18.0.0", "npm": ">=5.7.1" }, + "main": "lib/index.js", + "files": [ + "lib" + ], "dependencies": { "@ckeditor/ckeditor5-dev-translations": "^42.1.0", "chalk": "^3.0.0", @@ -17,7 +29,7 @@ "cssnano": "^6.0.3", "del": "^5.0.0", "esbuild-loader": "~3.0.1", - "fs-extra": "^9.1.0", + "fs-extra": "^11.2.0", "is-interactive": "^1.0.0", "javascript-stringify": "^1.6.0", "mini-css-extract-plugin": "^2.4.2", @@ -34,7 +46,7 @@ "through2": "^3.0.1" }, "devDependencies": { - "chai": "^4.1.2", + "chai": "^4.2.0", "mockery": "^2.1.0", "sinon": "^9.2.4", "vinyl": "^2.1.0" @@ -43,16 +55,13 @@ "test": "mocha './tests/**/*.js' --timeout 10000", "coverage": "nyc --reporter=lcov --reporter=text-summary yarn run test" }, - "files": [ - "lib" - ], - "author": "CKSource (http://cksource.com/)", - "license": "GPL-2.0-or-later", - "homepage": "https://github.com/ckeditor/ckeditor5-dev/tree/master/packages/ckeditor5-dev-utils", - "bugs": "https://github.com/ckeditor/ckeditor5/issues", - "repository": { - "type": "git", - "url": "https://github.com/ckeditor/ckeditor5-dev.git", - "directory": "packages/ckeditor5-dev-utils" - } + "depcheckIgnore": [ + "css-loader", + "del", + "esbuild-loader", + "postcss-loader", + "raw-loader", + "style-loader", + "mocha" + ] } diff --git a/packages/ckeditor5-dev-web-crawler/package.json b/packages/ckeditor5-dev-web-crawler/package.json index 58f888842..4b83478a5 100644 --- a/packages/ckeditor5-dev-web-crawler/package.json +++ b/packages/ckeditor5-dev-web-crawler/package.json @@ -3,20 +3,6 @@ "version": "42.1.0", "description": "Used to run a web crawler that checks for errors on specified pages.", "keywords": [], - "main": "lib/index.js", - "dependencies": { - "chalk": "^4.1.0", - "ora": "^5.2.0", - "puppeteer": "^19.7.5", - "strip-ansi": "^6.0.0" - }, - "engines": { - "node": ">=18.0.0", - "npm": ">=5.7.1" - }, - "files": [ - "lib" - ], "author": "CKSource (http://cksource.com/)", "license": "GPL-2.0-or-later", "homepage": "https://github.com/ckeditor/ckeditor5-dev/tree/master/packages/ckeditor5-dev-web-crawler", @@ -25,5 +11,19 @@ "type": "git", "url": "https://github.com/ckeditor/ckeditor5-dev.git", "directory": "packages/ckeditor5-dev-web-crawler" + }, + "engines": { + "node": ">=18.0.0", + "npm": ">=5.7.1" + }, + "main": "lib/index.js", + "files": [ + "lib" + ], + "dependencies": { + "chalk": "^4.1.0", + "ora": "^5.2.0", + "puppeteer": "^19.7.5", + "strip-ansi": "^6.0.0" } } diff --git a/packages/jsdoc-plugins/package.json b/packages/jsdoc-plugins/package.json index d226561e3..811e3ab8f 100644 --- a/packages/jsdoc-plugins/package.json +++ b/packages/jsdoc-plugins/package.json @@ -12,35 +12,35 @@ "short references", "inheritance" ], + "author": "CKSource (http://cksource.com/)", + "license": "MIT", + "homepage": "https://github.com/ckeditor/ckeditor5-dev/tree/master/packages/jsdoc-plugins", + "bugs": "https://github.com/ckeditor/ckeditor5/issues", + "repository": { + "type": "git", + "url": "https://github.com/ckeditor/ckeditor5-dev.git", + "directory": "packages/jsdoc-plugins" + }, + "engines": { + "node": ">=18.0.0", + "npm": ">=5.7.1" + }, + "files": [ + "lib" + ], "dependencies": { - "fs-extra": "^9.1.0", + "fs-extra": "^11.2.0", "lodash": "^4.17.15", - "jsdoc": "ckeditor/jsdoc#fixed-trailing-comment-doclets", - "upath": "^2.0.1" + "jsdoc": "ckeditor/jsdoc#fixed-trailing-comment-doclets" }, "devDependencies": { - "chai": "^4.1.2", + "chai": "^4.2.0", "glob": "^10.2.5", - "tmp": "^0.2.1" + "tmp": "^0.2.1", + "upath": "^2.0.1" }, "scripts": { "test": "mocha './tests/**/*.js' --timeout 10000", "coverage": "nyc --reporter=lcov --reporter=text-summary yarn run test" - }, - "engines": { - "node": ">=18.0.0", - "npm": ">=5.7.1" - }, - "files": [ - "lib" - ], - "author": "CKSource (http://cksource.com/)", - "license": "MIT", - "homepage": "https://github.com/ckeditor/ckeditor5-dev/tree/master/packages/jsdoc-plugins", - "bugs": "https://github.com/ckeditor/ckeditor5/issues", - "repository": { - "type": "git", - "url": "https://github.com/ckeditor/ckeditor5-dev.git", - "directory": "packages/jsdoc-plugins" } } diff --git a/packages/typedoc-plugins/package.json b/packages/typedoc-plugins/package.json index 2b91e8e84..56572852e 100644 --- a/packages/typedoc-plugins/package.json +++ b/packages/typedoc-plugins/package.json @@ -3,14 +3,27 @@ "version": "42.1.0", "description": "Various TypeDoc plugins developed by the CKEditor 5 team.", "keywords": [], - "main": "lib/index.js", + "author": "CKSource (http://cksource.com/)", + "license": "MIT", + "homepage": "https://github.com/ckeditor/ckeditor5-dev/tree/master/packages/typedoc-plugins", + "bugs": "https://github.com/ckeditor/ckeditor5/issues", + "repository": { + "type": "git", + "url": "https://github.com/ckeditor/ckeditor5-dev.git", + "directory": "packages/typedoc-plugins" + }, "engines": { "node": ">=18.0.0", "npm": ">=5.7.1" }, + "main": "lib/index.js", + "files": [ + "lib" + ], "devDependencies": { "chai": "^4.2.0", "fast-glob": "^3.2.4", + "sinon": "^9.2.4", "typedoc": "^0.23.15" }, "peerDependencies": { @@ -20,16 +33,7 @@ "test": "mocha './tests/**/*.js' --timeout 10000", "coverage": "nyc --reporter=lcov --reporter=text-summary yarn run test" }, - "files": [ - "lib" - ], - "author": "CKSource (http://cksource.com/)", - "license": "MIT", - "homepage": "https://github.com/ckeditor/ckeditor5-dev/tree/master/packages/typedoc-plugins", - "bugs": "https://github.com/ckeditor/ckeditor5/issues", - "repository": { - "type": "git", - "url": "https://github.com/ckeditor/ckeditor5-dev.git", - "directory": "packages/typedoc-plugins" - } + "depcheckIgnore": [ + "typedoc" + ] } diff --git a/scripts/bump-year.js b/scripts/bump-year.js index 07cf08d75..993315aaa 100644 --- a/scripts/bump-year.js +++ b/scripts/bump-year.js @@ -17,7 +17,7 @@ git commit -am "Internal: Bumped the year." && git push */ -require( '../packages/ckeditor5-dev-bump-year' ) +require( '@ckeditor/ckeditor5-dev-bump-year' ) .bumpYear( { cwd: process.cwd(), globPatterns: [ diff --git a/scripts/changelog.js b/scripts/changelog.js index 6b4e68605..af403d932 100755 --- a/scripts/changelog.js +++ b/scripts/changelog.js @@ -7,7 +7,7 @@ 'use strict'; -const { generateChangelogForMonoRepository } = require( '../packages/ckeditor5-dev-release-tools' ); +const { generateChangelogForMonoRepository } = require( '@ckeditor/ckeditor5-dev-release-tools' ); const parseArguments = require( './utils/parsearguments' ); const cliArguments = parseArguments( process.argv.slice( 2 ) ); From 0e35f4972c7c8dfdef8055f9b0dbc0cca46003d1 Mon Sep 17 00:00:00 2001 From: Kamil Piechaczek Date: Fri, 30 Aug 2024 11:54:03 +0200 Subject: [PATCH 7/8] Added missing mocha and introduced escaping shell parameters before executing a command. --- .../ckeditor5-dev-build-tools/package.json | 1 - packages/ckeditor5-dev-ci/package.json | 2 +- packages/ckeditor5-dev-docs/package.json | 1 + .../lib/tasks/commitandtag.js | 8 +++-- .../lib/tasks/push.js | 3 +- .../lib/tasks/reassignnpmtags.js | 4 ++- .../lib/utils/checkversionavailability.js | 5 +++- .../lib/utils/isversionpublishablefortag.js | 4 ++- .../ckeditor5-dev-release-tools/package.json | 2 ++ .../tests/tasks/commitandtag.js | 25 +++++++++++++++- .../tests/tasks/push.js | 13 ++++++++- .../tests/tasks/reassignnpmtags.js | 14 ++++++++- .../tests/utils/checkversionavailability.js | 29 ++++++++++--------- .../tests/utils/isversionpublishablefortag.js | 15 +++++++++- packages/ckeditor5-dev-stale-bot/package.json | 1 + packages/ckeditor5-dev-transifex/package.json | 1 + .../ckeditor5-dev-translations/package.json | 1 + packages/jsdoc-plugins/package.json | 1 + packages/typedoc-plugins/package.json | 1 + 19 files changed, 104 insertions(+), 27 deletions(-) diff --git a/packages/ckeditor5-dev-build-tools/package.json b/packages/ckeditor5-dev-build-tools/package.json index 82a8b5cdd..6a76b02d4 100644 --- a/packages/ckeditor5-dev-build-tools/package.json +++ b/packages/ckeditor5-dev-build-tools/package.json @@ -51,7 +51,6 @@ "rollup-plugin-styles": "^4.0.0", "rollup-plugin-svg-import": "^3.0.0", "source-map": "^0.7.4", - "source-map-js": "^1.2.0", "upath": "^2.0.1" }, "devDependencies": { diff --git a/packages/ckeditor5-dev-ci/package.json b/packages/ckeditor5-dev-ci/package.json index c53e8de4f..071db6280 100644 --- a/packages/ckeditor5-dev-ci/package.json +++ b/packages/ckeditor5-dev-ci/package.json @@ -40,8 +40,8 @@ }, "devDependencies": { "chai": "^4.2.0", - "proxyquire": "^2.1.3", "mocha": "^7.1.2", + "proxyquire": "^2.1.3", "mockery": "^2.1.0", "sinon": "^9.2.4" }, diff --git a/packages/ckeditor5-dev-docs/package.json b/packages/ckeditor5-dev-docs/package.json index bd6cd2196..ae1b0e32a 100644 --- a/packages/ckeditor5-dev-docs/package.json +++ b/packages/ckeditor5-dev-docs/package.json @@ -33,6 +33,7 @@ }, "devDependencies": { "chai": "^4.2.0", + "mocha": "^7.1.2", "proxyquire": "^2.1.3", "sinon": "^9.2.4", "sinon-chai": "^3.7.0" diff --git a/packages/ckeditor5-dev-release-tools/lib/tasks/commitandtag.js b/packages/ckeditor5-dev-release-tools/lib/tasks/commitandtag.js index a7549fe3f..510e1a7be 100644 --- a/packages/ckeditor5-dev-release-tools/lib/tasks/commitandtag.js +++ b/packages/ckeditor5-dev-release-tools/lib/tasks/commitandtag.js @@ -8,6 +8,7 @@ const { tools } = require( '@ckeditor/ckeditor5-dev-utils' ); const { toUnix } = require( 'upath' ); const { glob } = require( 'glob' ); +const shellEscape = require( 'shell-escape' ); /** * Creates a commit and a tag for specified version. @@ -34,9 +35,10 @@ module.exports = async function commitAndTag( { version, files, cwd = process.cw // Run the command separately for each file to avoid exceeding the maximum command length on Windows, which is 32767 characters. for ( const filePath of filePathsToAdd ) { - await tools.shExec( `git add ${ filePath }`, shExecOptions ); + await tools.shExec( `git add ${ shellEscape( [ filePath ] ) }`, shExecOptions ); } - await tools.shExec( `git commit --message "Release: v${ version }." --no-verify`, shExecOptions ); - await tools.shExec( `git tag v${ version }`, shExecOptions ); + const escapedVersion = shellEscape( [ version ] ); + await tools.shExec( `git commit --message "Release: v${ escapedVersion }." --no-verify`, shExecOptions ); + await tools.shExec( `git tag v${ escapedVersion }`, shExecOptions ); }; diff --git a/packages/ckeditor5-dev-release-tools/lib/tasks/push.js b/packages/ckeditor5-dev-release-tools/lib/tasks/push.js index 4acffd20d..ff6f1aebe 100644 --- a/packages/ckeditor5-dev-release-tools/lib/tasks/push.js +++ b/packages/ckeditor5-dev-release-tools/lib/tasks/push.js @@ -6,6 +6,7 @@ 'use strict'; const { tools } = require( '@ckeditor/ckeditor5-dev-utils' ); +const shellEscape = require( 'shell-escape' ); /** * Push the local changes to a remote server. @@ -23,7 +24,7 @@ module.exports = async function push( options ) { cwd = process.cwd() } = options; - const command = `git push origin ${ releaseBranch } v${ version }`; + const command = `git push origin ${ shellEscape( [ releaseBranch ] ) } v${ shellEscape( [ version ] ) }`; return tools.shExec( command, { cwd, verbosity: 'error', async: true } ); }; diff --git a/packages/ckeditor5-dev-release-tools/lib/tasks/reassignnpmtags.js b/packages/ckeditor5-dev-release-tools/lib/tasks/reassignnpmtags.js index fbd75087b..68d22f3fb 100644 --- a/packages/ckeditor5-dev-release-tools/lib/tasks/reassignnpmtags.js +++ b/packages/ckeditor5-dev-release-tools/lib/tasks/reassignnpmtags.js @@ -13,6 +13,7 @@ const chalk = require( 'chalk' ); const columns = require( 'cli-columns' ); const { tools } = require( '@ckeditor/ckeditor5-dev-utils' ); const util = require( 'util' ); +const shellEscape = require( 'shell-escape' ); const exec = util.promisify( require( 'child_process' ).exec ); const assertNpmAuthorization = require( '../utils/assertnpmauthorization' ); @@ -37,7 +38,8 @@ module.exports = async function reassignNpmTags( { npmOwner, version, packages } counter.start(); const updateTagPromises = packages.map( async packageName => { - const updateLatestTagRetryable = retry( () => exec( `npm dist-tag add ${ packageName }@${ version } latest` ) ); + const command = `npm dist-tag add ${ shellEscape( [ packageName ] ) }@${ shellEscape( [ version ] ) } latest`; + const updateLatestTagRetryable = retry( () => exec( command ) ); await updateLatestTagRetryable() .then( response => { if ( response.stdout ) { diff --git a/packages/ckeditor5-dev-release-tools/lib/utils/checkversionavailability.js b/packages/ckeditor5-dev-release-tools/lib/utils/checkversionavailability.js index 56c15f93c..547265df4 100644 --- a/packages/ckeditor5-dev-release-tools/lib/utils/checkversionavailability.js +++ b/packages/ckeditor5-dev-release-tools/lib/utils/checkversionavailability.js @@ -6,6 +6,7 @@ 'use strict'; const { tools } = require( '@ckeditor/ckeditor5-dev-utils' ); +const shellEscape = require( 'shell-escape' ); /** * Checks if the provided version for the package exists in the npm registry. @@ -18,7 +19,9 @@ const { tools } = require( '@ckeditor/ckeditor5-dev-utils' ); * @returns {Promise} */ module.exports = async function checkVersionAvailability( version, packageName ) { - return tools.shExec( `npm show ${ packageName }@${ version } version`, { verbosity: 'silent', async: true } ) + const command = `npm show ${ shellEscape( [ packageName ] ) }@${ shellEscape( [ version ] ) } version`; + + return tools.shExec( command, { verbosity: 'silent', async: true } ) .then( result => { // Explicit check for npm < 8.13.0, which does not return anything (an empty result) and it exits with a zero status code when // the version for the provided package does not exist in the npm registry. diff --git a/packages/ckeditor5-dev-release-tools/lib/utils/isversionpublishablefortag.js b/packages/ckeditor5-dev-release-tools/lib/utils/isversionpublishablefortag.js index 7e5f8f62d..2b9a13856 100644 --- a/packages/ckeditor5-dev-release-tools/lib/utils/isversionpublishablefortag.js +++ b/packages/ckeditor5-dev-release-tools/lib/utils/isversionpublishablefortag.js @@ -5,6 +5,7 @@ const { tools } = require( '@ckeditor/ckeditor5-dev-utils' ); const semver = require( 'semver' ); +const shellEscape = require( 'shell-escape' ); /** * This util aims to verify if the given `packageName` can be published with the given `version` on the `npmTag`. @@ -15,7 +16,8 @@ const semver = require( 'semver' ); * @return {Promise.} */ module.exports = async function isVersionPublishableForTag( packageName, version, npmTag ) { - const npmVersion = await tools.shExec( `npm view ${ packageName }@${ npmTag } version --silent`, { async: true, verbosity: 'silent' } ) + const command = `npm view ${ shellEscape( [ packageName ] ) }@${ shellEscape( [ npmTag ] ) } version --silent`; + const npmVersion = await tools.shExec( command, { async: true, verbosity: 'silent' } ) .then( value => value.trim() ) // An `npmTag` does not exist. .catch( () => null ); diff --git a/packages/ckeditor5-dev-release-tools/package.json b/packages/ckeditor5-dev-release-tools/package.json index 14479edff..77ee32aee 100644 --- a/packages/ckeditor5-dev-release-tools/package.json +++ b/packages/ckeditor5-dev-release-tools/package.json @@ -38,11 +38,13 @@ "lodash": "^4.17.15", "minimatch": "^3.0.4", "semver": "^7.5.3", + "shell-escape": "^0.2.0", "upath": "^2.0.1" }, "devDependencies": { "chai": "^4.2.0", "handlebars": "^4.7.6", + "mocha": "^7.1.2", "mockery": "^2.1.0", "mock-fs": "^5.1.2", "proxyquire": "^2.1.3", diff --git a/packages/ckeditor5-dev-release-tools/tests/tasks/commitandtag.js b/packages/ckeditor5-dev-release-tools/tests/tasks/commitandtag.js index 904230f9f..55d4975c1 100644 --- a/packages/ckeditor5-dev-release-tools/tests/tasks/commitandtag.js +++ b/packages/ckeditor5-dev-release-tools/tests/tasks/commitandtag.js @@ -25,13 +25,15 @@ describe( 'commitAndTag()', () => { }, glob: { glob: sinon.stub().returns( [] ) - } + }, + shellEscape: sinon.stub().callsFake( v => v[ 0 ] ) }; mockery.registerMock( '@ckeditor/ckeditor5-dev-utils', { tools: stubs.tools } ); mockery.registerMock( 'glob', stubs.glob ); + mockery.registerMock( 'shell-escape', stubs.shellEscape ); commitAndTag = require( '../../lib/tasks/commitandtag' ); } ); @@ -93,4 +95,25 @@ describe( 'commitAndTag()', () => { expect( stubs.tools.shExec.thirdCall.args[ 0 ] ).to.equal( 'git tag v1.0.0' ); } ); + + it( 'should escape arguments passed to a shell command', async () => { + stubs.glob.glob.resolves( [ + 'package.json', + 'README.md', + 'packages/custom-package/package.json', + 'packages/custom-package/README.md' + ] ); + + await commitAndTag( { + version: '1.0.0', + files: [ 'package.json', 'README.md', 'packages/*/package.json', 'packages/*/README.md' ] + } ); + + expect( stubs.shellEscape.callCount ).to.equal( 5 ); + expect( stubs.shellEscape.getCall( 0 ).args[ 0 ] ).to.deep.equal( [ 'package.json' ] ); + expect( stubs.shellEscape.getCall( 1 ).args[ 0 ] ).to.deep.equal( [ 'README.md' ] ); + expect( stubs.shellEscape.getCall( 2 ).args[ 0 ] ).to.deep.equal( [ 'packages/custom-package/package.json' ] ); + expect( stubs.shellEscape.getCall( 3 ).args[ 0 ] ).to.deep.equal( [ 'packages/custom-package/README.md' ] ); + expect( stubs.shellEscape.getCall( 4 ).args[ 0 ] ).to.deep.equal( [ '1.0.0' ] ); + } ); } ); diff --git a/packages/ckeditor5-dev-release-tools/tests/tasks/push.js b/packages/ckeditor5-dev-release-tools/tests/tasks/push.js index 0a61b3f32..8caff4b79 100644 --- a/packages/ckeditor5-dev-release-tools/tests/tasks/push.js +++ b/packages/ckeditor5-dev-release-tools/tests/tasks/push.js @@ -28,7 +28,8 @@ describe( 'dev-release-tools/tasks', () => { }, process: { cwd: sinon.stub( process, 'cwd' ).returns( 'current/working/dir' ) - } + }, + shellEscape: sinon.stub().callsFake( v => v[ 0 ] ) }; mockery.enable( { @@ -38,6 +39,7 @@ describe( 'dev-release-tools/tasks', () => { } ); mockery.registerMock( '@ckeditor/ckeditor5-dev-utils', stubs.devUtils ); + mockery.registerMock( 'shell-escape', stubs.shellEscape ); push = require( '../../lib/tasks/push' ); } ); @@ -81,5 +83,14 @@ describe( 'dev-release-tools/tasks', () => { async: true } ); } ); + + it( 'should escape arguments passed to a shell command', async () => { + stubs.devUtils.tools.shExec.resolves(); + await push( options ); + + expect( stubs.shellEscape.callCount ).to.equal( 2 ); + expect( stubs.shellEscape.firstCall.firstArg ).to.deep.equal( [ 'release' ] ); + expect( stubs.shellEscape.secondCall.firstArg ).to.deep.equal( [ '1.3.5' ] ); + } ); } ); } ); diff --git a/packages/ckeditor5-dev-release-tools/tests/tasks/reassignnpmtags.js b/packages/ckeditor5-dev-release-tools/tests/tasks/reassignnpmtags.js index ac927eba7..774bb1a52 100644 --- a/packages/ckeditor5-dev-release-tools/tests/tasks/reassignnpmtags.js +++ b/packages/ckeditor5-dev-release-tools/tests/tasks/reassignnpmtags.js @@ -46,7 +46,8 @@ describe( 'reassignNpmTags()', () => { util: { promisify: sinon.stub().callsFake( () => stubs.exec ) }, - exec: sinon.stub() + exec: sinon.stub(), + shellEscape: sinon.stub().callsFake( v => v[ 0 ] ) }; mockery.registerMock( '@ckeditor/ckeditor5-dev-utils', { tools: stubs.tools } ); @@ -54,6 +55,7 @@ describe( 'reassignNpmTags()', () => { mockery.registerMock( 'cli-columns', stubs.columns ); mockery.registerMock( 'chalk', stubs.chalk ); mockery.registerMock( 'util', stubs.util ); + mockery.registerMock( 'shell-escape', stubs.shellEscape ); reassignNpmTags = require( '../../lib/tasks/reassignnpmtags' ); } ); @@ -107,6 +109,16 @@ describe( 'reassignNpmTags()', () => { expect( npmDistTagAdd.secondCall.args[ 0 ] ).to.equal( 'npm dist-tag add package2@1.0.1 latest' ); } ); + it( 'should escape arguments passed to a shell command', async () => { + stubs.exec.withArgs( sinon.match( 'npm dist-tag add' ) ).resolves( { stdout: '+latest' } ); + + await reassignNpmTags( { npmOwner: 'authorized-user', version: '1.0.1', packages: [ 'package1' ] } ); + + expect( stubs.shellEscape.callCount ).to.equal( 2 ); + expect( stubs.shellEscape.firstCall.firstArg ).to.deep.equal( [ 'package1' ] ); + expect( stubs.shellEscape.secondCall.firstArg ).to.deep.equal( [ '1.0.1' ] ); + } ); + describe( 'UX', () => { it( 'should create a spinner before starting processing packages', async () => { await reassignNpmTags( { npmOwner: 'authorized-user', version: '1.0.1', packages: [] } ); diff --git a/packages/ckeditor5-dev-release-tools/tests/utils/checkversionavailability.js b/packages/ckeditor5-dev-release-tools/tests/utils/checkversionavailability.js index d6315861c..c0ea6d222 100644 --- a/packages/ckeditor5-dev-release-tools/tests/utils/checkversionavailability.js +++ b/packages/ckeditor5-dev-release-tools/tests/utils/checkversionavailability.js @@ -17,7 +17,8 @@ describe( 'dev-release-tools/utils', () => { sandbox = sinon.createSandbox(); stubs = { - shExec: sandbox.stub() + shExec: sandbox.stub(), + shellEscape: sinon.stub().callsFake( v => v[ 0 ] ) }; checkVersionAvailability = proxyquire( '../../lib/utils/checkversionavailability.js', { @@ -25,7 +26,8 @@ describe( 'dev-release-tools/utils', () => { tools: { shExec: stubs.shExec } - } + }, + 'shell-escape': stubs.shellEscape } ); } ); @@ -41,9 +43,6 @@ describe( 'dev-release-tools/utils', () => { expect( stubs.shExec.callCount ).to.equal( 1 ); expect( stubs.shExec.firstCall.args[ 0 ] ).to.equal( 'npm show stub-package@1.0.1 version' ); expect( result ).to.be.true; - } ) - .catch( () => { - throw new Error( 'Expected to be resolved.' ); } ); } ); @@ -55,9 +54,6 @@ describe( 'dev-release-tools/utils', () => { expect( stubs.shExec.callCount ).to.equal( 1 ); expect( stubs.shExec.firstCall.args[ 0 ] ).to.equal( 'npm show stub-package@1.0.1 version' ); expect( result ).to.be.true; - } ) - .catch( () => { - throw new Error( 'Expected to be resolved.' ); } ); } ); @@ -67,9 +63,6 @@ describe( 'dev-release-tools/utils', () => { return checkVersionAvailability( '1.0.1', 'stub-package' ) .then( result => { expect( result ).to.be.true; - } ) - .catch( () => { - throw new Error( 'Expected to be resolved.' ); } ); } ); @@ -79,9 +72,6 @@ describe( 'dev-release-tools/utils', () => { return checkVersionAvailability( '1.0.1', 'stub-package' ) .then( result => { expect( result ).to.be.false; - } ) - .catch( () => { - throw new Error( 'Expected to be resolved.' ); } ); } ); @@ -96,5 +86,16 @@ describe( 'dev-release-tools/utils', () => { expect( error.message ).to.equal( 'Unknown error.' ); } ); } ); + + it( 'should escape arguments passed to a shell command', async () => { + stubs.shExec.rejects( new Error( 'npm ERR! code E404' ) ); + + return checkVersionAvailability( '1.0.1', 'stub-package' ) + .then( () => { + expect( stubs.shellEscape.callCount ).to.equal( 2 ); + expect( stubs.shellEscape.firstCall.firstArg ).to.deep.equal( [ 'stub-package' ] ); + expect( stubs.shellEscape.secondCall.firstArg ).to.deep.equal( [ '1.0.1' ] ); + } ); + } ); } ); } ); diff --git a/packages/ckeditor5-dev-release-tools/tests/utils/isversionpublishablefortag.js b/packages/ckeditor5-dev-release-tools/tests/utils/isversionpublishablefortag.js index 6f74039eb..37e025cc0 100644 --- a/packages/ckeditor5-dev-release-tools/tests/utils/isversionpublishablefortag.js +++ b/packages/ckeditor5-dev-release-tools/tests/utils/isversionpublishablefortag.js @@ -21,7 +21,8 @@ describe( 'dev-release-tools/isVersionPublishableForTag', () => { tools: { shExec: sinon.stub() } - } + }, + shellEscape: sinon.stub().callsFake( v => v[ 0 ] ) }; mockery.enable( { @@ -31,6 +32,7 @@ describe( 'dev-release-tools/isVersionPublishableForTag', () => { } ); mockery.registerMock( 'semver', stub.semver ); + mockery.registerMock( 'shell-escape', stub.shellEscape ); mockery.registerMock( '@ckeditor/ckeditor5-dev-utils', stub.devUtils ); isVersionPublishableForTag = require( '../../lib/utils/isversionpublishablefortag' ); @@ -77,4 +79,15 @@ describe( 'dev-release-tools/isVersionPublishableForTag', () => { expect( stub.devUtils.tools.shExec.callCount ).to.equal( 1 ); expect( stub.devUtils.tools.shExec.firstCall.firstArg ).to.equal( 'npm view package-name@alpha version --silent' ); } ); + + it( 'should escape arguments passed to a shell command', async () => { + stub.semver.lte.returns( false ); + stub.devUtils.tools.shExec.resolves( '1.0.0\n' ); + + await isVersionPublishableForTag( 'package-name', '1.0.0', 'alpha' ); + + expect( stub.shellEscape.callCount ).to.equal( 2 ); + expect( stub.shellEscape.firstCall.firstArg ).to.deep.equal( [ 'package-name' ] ); + expect( stub.shellEscape.secondCall.firstArg ).to.deep.equal( [ 'alpha' ] ); + } ); } ); diff --git a/packages/ckeditor5-dev-stale-bot/package.json b/packages/ckeditor5-dev-stale-bot/package.json index a4e493e83..e50915cb1 100644 --- a/packages/ckeditor5-dev-stale-bot/package.json +++ b/packages/ckeditor5-dev-stale-bot/package.json @@ -36,6 +36,7 @@ }, "devDependencies": { "chai": "^4.2.0", + "mocha": "^7.1.2", "sinon": "^9.2.4", "proxyquire": "^2.1.3" }, diff --git a/packages/ckeditor5-dev-transifex/package.json b/packages/ckeditor5-dev-transifex/package.json index edc0efcd5..7af310952 100644 --- a/packages/ckeditor5-dev-transifex/package.json +++ b/packages/ckeditor5-dev-transifex/package.json @@ -33,6 +33,7 @@ }, "devDependencies": { "chai": "^4.2.0", + "mocha": "^7.1.2", "mockery": "^2.1.0", "proxyquire": "^2.1.3", "sinon": "^9.2.4" diff --git a/packages/ckeditor5-dev-translations/package.json b/packages/ckeditor5-dev-translations/package.json index 120900726..c0fbb7c9f 100644 --- a/packages/ckeditor5-dev-translations/package.json +++ b/packages/ckeditor5-dev-translations/package.json @@ -30,6 +30,7 @@ }, "devDependencies": { "chai": "^4.2.0", + "mocha": "^7.1.2", "proxyquire": "^2.1.3", "sinon": "^9.2.4" }, diff --git a/packages/jsdoc-plugins/package.json b/packages/jsdoc-plugins/package.json index 811e3ab8f..7d0f3cbbd 100644 --- a/packages/jsdoc-plugins/package.json +++ b/packages/jsdoc-plugins/package.json @@ -36,6 +36,7 @@ "devDependencies": { "chai": "^4.2.0", "glob": "^10.2.5", + "mocha": "^7.1.2", "tmp": "^0.2.1", "upath": "^2.0.1" }, diff --git a/packages/typedoc-plugins/package.json b/packages/typedoc-plugins/package.json index 56572852e..64cf48771 100644 --- a/packages/typedoc-plugins/package.json +++ b/packages/typedoc-plugins/package.json @@ -23,6 +23,7 @@ "devDependencies": { "chai": "^4.2.0", "fast-glob": "^3.2.4", + "mocha": "^7.1.2", "sinon": "^9.2.4", "typedoc": "^0.23.15" }, From d102ba499d1513c027ed4636802246cdf0354c3d Mon Sep 17 00:00:00 2001 From: Kamil Piechaczek Date: Fri, 30 Aug 2024 12:30:56 +0200 Subject: [PATCH 8/8] Display the coverage path and mute npm output. --- scripts/runtest.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/runtest.js b/scripts/runtest.js index 7bf015532..2b9f11970 100644 --- a/scripts/runtest.js +++ b/scripts/runtest.js @@ -39,7 +39,7 @@ function main() { const testScript = coverage ? 'coverage' : 'test'; try { - execSync( `npm run ${ testScript } --silent`, { + execSync( `npm run --silent ${ testScript }`, { stdio: 'inherit', cwd: path.join( cwd, relativePath ) } ); @@ -60,6 +60,8 @@ function main() { fs.writeFileSync( coverageFile, content, { flag: 'as' } ); } + + console.log( chalk.cyan( `\nCoverage status stored in "${ chalk.underline( coverageFile ) }".` ) ); } if ( ignoredPackages.length ) {