Review fixes

This commit is contained in:
Convly 2023-01-25 16:31:51 +01:00
parent 3346f92fd0
commit c631b7f77c
12 changed files with 74 additions and 104 deletions

View File

@ -10,8 +10,8 @@ module.exports = {
globals: { globals: {
strapi: false, strapi: false,
}, },
// Instead of extending (which includes values that interfere with this configuration), only take the rules field
rules: { rules: {
// Instead of extending (which includes values that interfere with this configuration), only take the rules field
...require('./.eslintrc.back.js').rules, ...require('./.eslintrc.back.js').rules,
'import/no-extraneous-dependencies': ['error', { devDependencies: ['**/*.test.ts'] }], 'import/no-extraneous-dependencies': ['error', { devDependencies: ['**/*.test.ts'] }],
// TODO: The following rules from @strapi/eslint-config/typescript are disabled because they're causing problems we need to solve or fix // TODO: The following rules from @strapi/eslint-config/typescript are disabled because they're causing problems we need to solve or fix

View File

@ -12,8 +12,8 @@ module.exports = {
ecmaVersion: 2020, ecmaVersion: 2020,
}, },
overrides: [ overrides: [
{
// Backend javascript // Backend javascript
{
files: ['packages/**/*.js', 'test/**/*.js', 'scripts/**/*.js', 'jest.*.js'], files: ['packages/**/*.js', 'test/**/*.js', 'scripts/**/*.js', 'jest.*.js'],
excludedFiles: frontPaths, excludedFiles: frontPaths,
...require('./.eslintrc.back.js'), ...require('./.eslintrc.back.js'),

View File

@ -1,6 +1,6 @@
'use strict'; 'use strict';
const { register: registerDataTransferRoute } = require('@strapi/data-transfer/lib/strapi'); // const { register: registerDataTransferRoute } = require('@strapi/data-transfer/lib/strapi');
const registerAdminPanelRoute = require('./routes/serve-admin-panel'); const registerAdminPanelRoute = require('./routes/serve-admin-panel');
const adminAuthStrategy = require('./strategies/admin'); const adminAuthStrategy = require('./strategies/admin');
@ -17,10 +17,10 @@ module.exports = ({ strapi }) => {
registerAdminPanelRoute({ strapi }); registerAdminPanelRoute({ strapi });
} }
if ( // if (
process.env.STRAPI_EXPERIMENTAL === 'true' && // process.env.STRAPI_EXPERIMENTAL === 'true' &&
process.env.STRAPI_DISABLE_REMOTE_DATA_TRANSFER !== 'true' // process.env.STRAPI_DISABLE_REMOTE_DATA_TRANSFER !== 'true'
) { // ) {
registerDataTransferRoute(strapi); // registerDataTransferRoute(strapi);
} // }
}; };

View File

@ -175,6 +175,7 @@ export const extendExpectForDataTransferTests = () => {
const missing = destinationStages.filter((stage) => { const missing = destinationStages.filter((stage) => {
if (provider[stage]) { if (provider[stage]) {
try { try {
// TODO: why is mock.calls an empty array? maybe an async function call that doesn't resolve?
// expect(provider[stage]).toHaveBeenCalledOnce(); // expect(provider[stage]).toHaveBeenCalledOnce();
expect(provider[stage].mock.results.length).toEqual(times); expect(provider[stage].mock.results.length).toEqual(times);
return false; return false;

View File

@ -99,16 +99,6 @@ const metadata = {
createdAt: '2022-11-23T09:26:43.463Z', createdAt: '2022-11-23T09:26:43.463Z',
strapi: { strapi: {
version: '1.2.3', version: '1.2.3',
plugins: [
{
name: 'content-manager',
version: '1.2.3',
},
{
name: 'content-type-builder',
version: '1.2.3',
},
],
}, },
}; };

View File

@ -476,9 +476,8 @@ class TransferEngine<
stream stream
.pipe(destination) .pipe(destination)
.on('error', (e) => { .on('error', (e) => {
// TODO ? this.#reportError(e, 'error');
// this.#reportError(e, 'error'); destination.destroy(e);
// destination.destroy(e);
reject(e); reject(e);
}) })
.on('close', resolve); .on('close', resolve);

View File

@ -77,8 +77,8 @@ class LocalStrapiDestinationProvider implements IDestinationProvider {
return restore.deleteRecords(this.strapi, this.options.restore); return restore.deleteRecords(this.strapi, this.options.restore);
} }
async rollback(e: Error): Promise<void> { rollback(): void {
await this.transaction?.rollback(); this.transaction?.rollback();
} }
async beforeTransfer() { async beforeTransfer() {
@ -101,17 +101,10 @@ class LocalStrapiDestinationProvider implements IDestinationProvider {
const strapiVersion = strapi.config.get('info.strapi'); const strapiVersion = strapi.config.get('info.strapi');
const createdAt = new Date().toISOString(); const createdAt = new Date().toISOString();
const plugins = Object.keys(strapi.plugins);
return { return {
createdAt, createdAt,
strapi: { strapi: {
version: strapiVersion, version: strapiVersion,
plugins: plugins.map((name) => ({
name,
// TODO: Get the plugin actual version when it'll be available
version: strapiVersion,
})),
}, },
}; };
} }

View File

@ -49,17 +49,10 @@ class LocalStrapiSourceProvider implements ISourceProvider {
const strapiVersion = strapi.config.get('info.strapi'); const strapiVersion = strapi.config.get('info.strapi');
const createdAt = new Date().toISOString(); const createdAt = new Date().toISOString();
const plugins = Object.keys(strapi.plugins);
return { return {
createdAt, createdAt,
strapi: { strapi: {
version: strapiVersion, version: strapiVersion,
plugins: plugins.map((name) => ({
name,
// TODO: Get the plugin actual version when it'll be available
version: strapiVersion,
})),
}, },
}; };
} }

View File

@ -149,7 +149,7 @@ export const createTransferHandler =
const { controller } = state; const { controller } = state;
// TODO: (re)move this check // TODO: (re)move this check
// It shouldn't be possible to strart a pull transfer for now, so reaching // It shouldn't be possible to start a pull transfer for now, so reaching
// this code should be impossible too, but this has been added by security // this code should be impossible too, but this has been added by security
if (state.transfer?.kind === 'pull') { if (state.transfer?.kind === 'pull') {
return callback(new ProviderTransferError('Pull transfer not implemented')); return callback(new ProviderTransferError('Pull transfer not implemented'));

View File

@ -5,11 +5,6 @@ import type { Readable } from 'stream';
export interface IMetadata { export interface IMetadata {
strapi?: { strapi?: {
version?: string; version?: string;
plugins?: {
name: string;
version: string;
}[];
}; };
createdAt?: string; createdAt?: string;

View File

@ -17,10 +17,9 @@ const packageJSON = require('../package.json');
const { const {
promptEncryptionKey, promptEncryptionKey,
confirmMessage, confirmMessage,
parseURL,
forceOption, forceOption,
} = require('../lib/commands/utils/commander'); } = require('../lib/commands/utils/commander');
const { ifOptions, assertUrlHasProtocol, exitWith } = require('../lib/commands/utils/helpers'); const { exitWith } = require('../lib/commands/utils/helpers');
const { const {
excludeOption, excludeOption,
onlyOption, onlyOption,
@ -269,59 +268,59 @@ program
.option('-s, --silent', `Run the generation silently, without any output`, false) .option('-s, --silent', `Run the generation silently, without any output`, false)
.action(getLocalScript('ts/generate-types')); .action(getLocalScript('ts/generate-types'));
if (process.env.STRAPI_EXPERIMENTAL === 'true') { // if (process.env.STRAPI_EXPERIMENTAL === 'true') {
// `$ strapi transfer` // // `$ strapi transfer`
program // program
.command('transfer') // .command('transfer')
.description('Transfer data from one source to another') // .description('Transfer data from one source to another')
.allowExcessArguments(false) // .allowExcessArguments(false)
.addOption( // .addOption(
new Option( // new Option(
'--from <sourceURL>', // '--from <sourceURL>',
`URL of the remote Strapi instance to get data from` // `URL of the remote Strapi instance to get data from`
).argParser(parseURL) // ).argParser(parseURL)
) // )
.addOption( // .addOption(
new Option( // new Option(
'--to <destinationURL>', // '--to <destinationURL>',
`URL of the remote Strapi instance to send data to` // `URL of the remote Strapi instance to send data to`
).argParser(parseURL) // ).argParser(parseURL)
) // )
.addOption(forceOption) // .addOption(forceOption)
// Validate URLs // // Validate URLs
.hook( // .hook(
'preAction', // 'preAction',
ifOptions( // ifOptions(
(opts) => opts.from, // (opts) => opts.from,
(thisCommand) => assertUrlHasProtocol(thisCommand.opts().from, ['https:', 'http:']) // (thisCommand) => assertUrlHasProtocol(thisCommand.opts().from, ['https:', 'http:'])
) // )
) // )
.hook( // .hook(
'preAction', // 'preAction',
ifOptions( // ifOptions(
(opts) => opts.to, // (opts) => opts.to,
(thisCommand) => assertUrlHasProtocol(thisCommand.opts().to, ['https:', 'http:']) // (thisCommand) => assertUrlHasProtocol(thisCommand.opts().to, ['https:', 'http:'])
) // )
) // )
.hook( // .hook(
'preAction', // 'preAction',
ifOptions( // ifOptions(
(opts) => !opts.from && !opts.to, // (opts) => !opts.from && !opts.to,
() => exitWith(1, 'At least one source (from) or destination (to) option must be provided') // () => exitWith(1, 'At least one source (from) or destination (to) option must be provided')
) // )
) // )
.addOption(forceOption) // .addOption(forceOption)
.addOption(excludeOption) // .addOption(excludeOption)
.addOption(onlyOption) // .addOption(onlyOption)
.hook('preAction', validateExcludeOnly) // .hook('preAction', validateExcludeOnly)
.hook( // .hook(
'preAction', // 'preAction',
confirmMessage( // confirmMessage(
'The import will delete all data in the remote database. Are you sure you want to proceed?' // 'The import will delete all data in the remote database. Are you sure you want to proceed?'
) // )
) // )
.action(getLocalScript('transfer/transfer')); // .action(getLocalScript('transfer/transfer'));
} // }
// `$ strapi export` // `$ strapi export`
program program

View File

@ -21,7 +21,7 @@ const {
} = require('./utils'); } = require('./utils');
/** /**
* @typedef ImportCommandOptions Options given to the CLI import command * @typedef ExportCommandOptions Options given to the CLI import command
* *
* @property {string} [file] The file path to import * @property {string} [file] The file path to import
* @property {boolean} [encrypt] Used to encrypt the final archive * @property {boolean} [encrypt] Used to encrypt the final archive
@ -34,11 +34,11 @@ const logger = console;
const BYTES_IN_MB = 1024 * 1024; const BYTES_IN_MB = 1024 * 1024;
/** /**
* Import command. * Export command.
* *
* It transfers data from a local file to a local strapi instance * It transfers data from a local Strapi instance to a file
* *
* @param {ImportCommandOptions} opts * @param {ExportCommandOptions} opts
*/ */
module.exports = async (opts) => { module.exports = async (opts) => {
// Validate inputs from Commander // Validate inputs from Commander
@ -135,7 +135,7 @@ const createSourceProvider = (strapi) => {
/** /**
* It creates a local file destination provider based on the given options * It creates a local file destination provider based on the given options
* *
* @param {ImportCommandOptions} opts * @param {ExportCommandOptions} opts
*/ */
const createDestinationProvider = (opts) => { const createDestinationProvider = (opts) => {
const { file, compress, encrypt, key, maxSizeJsonl } = opts; const { file, compress, encrypt, key, maxSizeJsonl } = opts;