chore: convert other packages to pack-up (#18339)

* chore: convert logger to pack-up

* chore: convert generators to TS

* chore: convert generators/app

* chore: convert core/types

* chore: preserve modules for `generators/app`
This commit is contained in:
Josh 2023-10-12 15:01:25 +01:00 committed by GitHub
parent 293219f39f
commit 0b13b1b50a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 107 additions and 50 deletions

View File

@ -1,2 +0,0 @@
// this is a failsafe file in case the package gets required as code
module.exports = null;

View File

@ -26,21 +26,23 @@
"url": "https://strapi.io"
}
],
"main": "index.js",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"source": "./src/index.ts",
"types": "./dist/index.d.ts",
"files": [
"./dist/**/!(*.d.ts.map)",
"index.js"
"./dist"
],
"scripts": {
"build": "run -T tsc -p tsconfig.build.json",
"build:ts": "run build",
"build": "pack-up build",
"clean": "run -T rimraf ./dist",
"lint": "run -T eslint .",
"prepublishOnly": "yarn clean && yarn build",
"test:ts": "run -T tsc --noEmit",
"test:unit": "run -T jest",
"test:unit:watch": "run -T jest --watch",
"watch": "run -T tsc -p tsconfig.build.json -w --preserveWatchOutput"
"watch": "pack-up watch"
},
"dependencies": {
"@koa/cors": "3.4.3",
@ -56,6 +58,7 @@
"node-schedule": "2.1.0"
},
"devDependencies": {
"@strapi/pack-up": "workspace:*",
"@strapi/ts-zen": "^0.2.0",
"@types/jest": "29.5.2",
"@types/koa": "2.13.4",

View File

@ -39,20 +39,24 @@ describe('Utils.Object', () => {
test('PickBy', () => {
type('PickByString').isMappedType({
properties: {
// @ts-expect-error - Wants to be string[]
foo: t.stringLiteral('bar'),
bar: t.stringLiteral('foo'),
},
});
type('PickByNumber').isMappedType({
properties: {
// @ts-expect-error - Wants to be string[]
foobar: t.numberLiteral(2),
},
});
type('PickByNever').isMappedType({
// @ts-expect-error - Thinks it _must_ have a property
properties: {},
});
type('PickByUnknown').isMappedType({
properties: {
// @ts-expect-error - Wants to be string[]
foobar: t.numberLiteral(2),
foo: t.stringLiteral('bar'),
bar: t.stringLiteral('foo'),
@ -60,7 +64,9 @@ describe('Utils.Object', () => {
});
type('PickByObj').isMappedType({
properties: {
// @ts-expect-error - Wants to be string[]
foo: t.mappedType({ properties: { x: t.stringLiteral('bar') } }),
// @ts-expect-error - Wants to be string[]
bar: t.mappedType({ properties: { x: t.stringLiteral('foo') } }),
},
});

View File

@ -29,18 +29,20 @@
}
],
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"source": "./src/index.ts",
"types": "./dist/index.d.ts",
"files": [
"./dist"
],
"scripts": {
"build": "run -T tsc && run copy-files",
"build:ts": "run build",
"build": "pack-up build && run copy-files",
"clean": "run -T rimraf ./dist",
"copy-files": "copyfiles -u 1 -a 'src/resources/files/**/*' 'src/resources/dot-files/**/*' 'src/resources/**/*.template' dist",
"lint": "run -T eslint .",
"prepublishOnly": "yarn clean && yarn build",
"watch": "run -T tsc -w --preserveWatchOutput"
"test:ts": "run -T tsc --noEmit",
"watch": "pack-up watch"
},
"dependencies": {
"@sentry/node": "6.19.7",
@ -56,6 +58,7 @@
"tar": "6.1.13"
},
"devDependencies": {
"@strapi/pack-up": "workspace:*",
"copyfiles": "2.4.1"
},
"engines": {

View File

@ -0,0 +1,8 @@
// eslint-disable-next-line import/no-extraneous-dependencies
import { defineConfig } from '@strapi/pack-up';
export default defineConfig({
externals: ['crypto', 'fs', 'node:fs', 'node:os', 'node:path', 'node:readline', 'os', 'path'],
preserveModules: true,
runtime: 'node',
});

View File

@ -12,6 +12,9 @@ import mergeTemplate from './utils/merge-template.js';
import tryGitInit from './utils/git';
import packageJSON from './resources/json/common/package.json';
import jsconfig from './resources/json/js/jsconfig.json';
import adminTsconfig from './resources/json/ts/tsconfig-admin.json';
import serverTsconfig from './resources/json/ts/tsconfig-server.json';
import { createDatabaseConfig, generateDbEnvariables } from './resources/templates/database';
import createEnvFile from './resources/templates/env';
import { Configuration, Scope, isStderrError } from './types';
@ -79,31 +82,27 @@ export default async function createProject(
await trackUsage({ event: 'didWritePackageJSON', scope });
if (useTypescript) {
const tsJSONDir = join(__dirname, 'resources/json/ts');
const filesMap = {
'tsconfig-admin.json.js': 'src/admin',
'tsconfig-server.json.js': '.',
};
for (const [fileName, path] of Object.entries(filesMap)) {
const srcPath = join(tsJSONDir, fileName);
const destPath = join(rootPath, path, 'tsconfig.json');
const json = require(srcPath).default();
await fse.writeJSON(destPath, json, { spaces: 2 });
if (fileName === 'tsconfig-admin.json.js') {
await fse.writeJSON(destPath, adminTsconfig(), { spaces: 2 });
}
if (fileName === 'tsconfig-server.json.js') {
await fse.writeJSON(destPath, serverTsconfig(), { spaces: 2 });
}
}
} else {
const jsJSONDir = join(__dirname, 'resources/json/js');
const filesMap = { 'jsconfig.json.js': '.' };
for (const [fileName, path] of Object.entries(filesMap)) {
const srcPath = join(jsJSONDir, fileName);
for (const [, path] of Object.entries(filesMap)) {
const destPath = join(rootPath, path, 'jsconfig.json');
const json = require(srcPath).default();
await fse.writeJSON(destPath, json, { spaces: 2 });
await fse.writeJSON(destPath, jsconfig(), { spaces: 2 });
}
}

View File

@ -0,0 +1,7 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "dist"
},
"exclude": ["**/__tests__/**", "src/resources/files"]
}

View File

@ -3,6 +3,6 @@
"compilerOptions": {
"noEmit": true
},
"include": ["src"],
"include": ["src", "packup.config.ts"],
"exclude": ["node_modules"]
}

View File

@ -1,9 +1,5 @@
{
"extends": "tsconfig/base.json",
"compilerOptions": {
"outDir": "dist",
"target": "ES2021"
},
"include": ["src"],
"exclude": ["node_modules", "**/__tests__/**", "src/resources/files"]
"exclude": ["node_modules", "src/resources/files"]
}

View File

@ -28,20 +28,22 @@
}
],
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"source": "./src/index.ts",
"types": "./dist/index.d.ts",
"files": [
"./dist"
],
"scripts": {
"build": "run -T tsc && run copy-files",
"build:ts": "run build",
"build": "pack-up build && run copy-files",
"clean": "run -T rimraf ./dist",
"copy-files": "copyfiles -u 1 -a 'src/templates/**/*' 'src/files/**/*' dist",
"lint": "run -T eslint .",
"prepublishOnly": "yarn clean && yarn build",
"test:ts": "run -T tsc --noEmit",
"test:unit": "run -T jest",
"test:unit:watch": "run -T jest --watch",
"watch": "run -T tsc -w --preserveWatchOutput"
"watch": "pack-up watch"
},
"dependencies": {
"@sindresorhus/slugify": "1.1.0",
@ -55,6 +57,7 @@
"pluralize": "8.0.0"
},
"devDependencies": {
"@strapi/pack-up": "workspace:*",
"eslint-config-custom": "4.14.4",
"tsconfig": "4.14.4"
},

View File

@ -0,0 +1,14 @@
// eslint-disable-next-line import/no-extraneous-dependencies
import { defineConfig } from '@strapi/pack-up';
export default defineConfig({
bundles: [
{
source: './src/plopfile.ts',
require: './dist/plopfile.js',
import: './dist/plopfile.mjs',
},
],
externals: ['node:path', 'path'],
runtime: 'node',
});

View File

@ -0,0 +1,7 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "dist"
},
"exclude": ["**/__tests__/**", "src/files", "src/templates"]
}

View File

@ -3,6 +3,6 @@
"compilerOptions": {
"noEmit": true
},
"include": ["src"],
"include": ["src", "packup.config.ts"],
"exclude": ["node_modules"]
}

View File

@ -1,8 +1,5 @@
{
"extends": "tsconfig/base.json",
"compilerOptions": {
"outDir": "dist"
},
"include": ["src"],
"exclude": ["node_modules", "**/__tests__/**", "src/files", "src/templates"]
"exclude": ["node_modules", "src/files", "src/templates"]
}

View File

@ -24,23 +24,26 @@
}
],
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"source": "./src/index.ts",
"types": "./dist/index.d.ts",
"files": [
"./dist"
],
"scripts": {
"build": "run -T tsc",
"build:ts": "run -T tsc",
"build": "pack-up build",
"clean": "run -T rimraf ./dist",
"lint": "run -T eslint .",
"prepublishOnly": "yarn clean && yarn build",
"watch": "run -T tsc -w --preserveWatchOutput"
"test:ts": "run -T tsc --noEmit",
"watch": "pack-up watch"
},
"dependencies": {
"lodash": "4.17.21",
"winston": "3.10.0"
},
"devDependencies": {
"@strapi/pack-up": "workspace:*",
"eslint-config-custom": "4.14.4",
"tsconfig": "4.14.4"
},

View File

@ -0,0 +1,6 @@
// eslint-disable-next-line import/no-extraneous-dependencies
import { defineConfig } from '@strapi/pack-up';
export default defineConfig({
runtime: 'node',
});

View File

@ -1,3 +1,4 @@
export { default as prettyPrint, PrettyPrintOptions } from './pretty-print';
export { default as prettyPrint } from './pretty-print';
export type { PrettyPrintOptions } from './pretty-print';
export { default as levelFilter } from './level-filter';
export { default as excludeColors } from './exclude-colors';

View File

@ -0,0 +1,8 @@
{
"extends": "tsconfig/base.json",
"compilerOptions": {
"outDir": "dist"
},
"include": ["src"],
"exclude": ["node_modules", "**/__tests__/**"]
}

View File

@ -1,6 +1,3 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"noEmit": true,
},
"extends": "./tsconfig"
}

View File

@ -1,8 +1,5 @@
{
"extends": "tsconfig/base.json",
"compilerOptions": {
"outDir": "dist"
},
"include": ["src"],
"exclude": ["node_modules", "**/__tests__/**"]
"include": ["src", "packup.config.ts"],
"exclude": ["node_modules"]
}

View File

@ -4,7 +4,7 @@ const path = require('path');
const fs = require('fs');
const rimraf = require('rimraf');
const execa = require('execa');
const generateNew = require('../../packages/generators/app/dist/generate-new').default;
const generateNew = require('../../packages/generators/app/dist/generate-new');
/**
* Deletes a test app

View File

@ -7639,6 +7639,7 @@ __metadata:
resolution: "@strapi/generate-new@workspace:packages/generators/app"
dependencies:
"@sentry/node": 6.19.7
"@strapi/pack-up": "workspace:*"
chalk: ^4.1.2
copyfiles: 2.4.1
execa: 5.1.1
@ -7658,6 +7659,7 @@ __metadata:
resolution: "@strapi/generators@workspace:packages/generators/generators"
dependencies:
"@sindresorhus/slugify": 1.1.0
"@strapi/pack-up": "workspace:*"
"@strapi/typescript-utils": 4.14.4
"@strapi/utils": 4.14.4
chalk: 4.1.2
@ -7750,6 +7752,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "@strapi/logger@workspace:packages/utils/logger"
dependencies:
"@strapi/pack-up": "workspace:*"
eslint-config-custom: 4.14.4
lodash: 4.17.21
tsconfig: 4.14.4
@ -8347,6 +8350,7 @@ __metadata:
"@koa/router": 10.1.1
"@strapi/database": 4.14.4
"@strapi/logger": 4.14.4
"@strapi/pack-up": "workspace:*"
"@strapi/permissions": 4.14.4
"@strapi/ts-zen": ^0.2.0
"@strapi/utils": 4.14.4