Skip to content

Commit

Permalink
vx: clean up hand crafted paths
Browse files Browse the repository at this point in the history
  • Loading branch information
ealush committed Apr 1, 2022
1 parent bc01a88 commit b99e817
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 31 deletions.
2 changes: 1 addition & 1 deletion tsconfig.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions vx/config/jest/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const ignoreGeneratedExports = moduleAliases().reduce((allExports, current) => {

const x = path
.join(...current.absolute.split(find))
.replace('.ts', '/package.json');
.replace('.ts', `/${opts.fileNames.PACKAGE_JSON}`);

return allExports.concat(x);
}, []);
Expand Down Expand Up @@ -49,7 +49,7 @@ module.exports = (custom = {}) => ({
'ts-jest': {
tsconfig: usePackage()
? vxPath.packageTsConfig()
: path.join(vxPath.ROOT_PATH, vxPath.TSCONFIG_JSON),
: path.join(vxPath.ROOT_PATH, opts.fileNames.TSCONFIG_JSON),
diagnostics: {
// Essentially ignoring "any" errors in TESTS
ignoreCodes: [
Expand All @@ -69,11 +69,11 @@ module.exports = (custom = {}) => ({
preset: 'ts-jest',
rootDir: vxPath.ROOT_PATH,
roots: ['<rootDir>'],
setupFiles: [path.resolve(vxPath.JEST_CONFIG_PATH, 'jest.setup.ts')].concat(
setupPerPackage
),
setupFiles: [
path.resolve(vxPath.JEST_CONFIG_PATH, opts.fileNames.JEST_SETUP),
].concat(setupPerPackage),
setupFilesAfterEnv: [
path.resolve(vxPath.JEST_CONFIG_PATH, 'jest.setupAfterEnv.ts'),
path.resolve(vxPath.JEST_CONFIG_PATH, opts.fileNames.JEST_SETUP_AFTER_ENV),
].concat(setupAfterEnvPerPackage),
testEnvironment: 'node',
testMatch: [vxPath.packageSrc('*', `**/${opts.dir.TESTS}/*.(spec|test).ts`)],
Expand Down
3 changes: 1 addition & 2 deletions vx/config/rollup/plugins/addCJSPackageJson.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ const path = require('path');
const fse = require('fs-extra');

const opts = require('vx/opts');
const vxPath = require('vx/vxPath');

module.exports = addEsPackageJson;

Expand All @@ -17,7 +16,7 @@ function addEsPackageJson() {

const packageJsonPath = path.join(
path.dirname(file),
vxPath.PACKAGE_JSON
opts.fileNames.PACKAGE_JSON
);

if (fse.existsSync(packageJsonPath)) {
Expand Down
3 changes: 1 addition & 2 deletions vx/config/rollup/plugins/addModulePackageJson.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ const path = require('path');
const fse = require('fs-extra');

const opts = require('vx/opts');
const vxPath = require('vx/vxPath');

module.exports = addEsPackageJson;

Expand All @@ -17,7 +16,7 @@ function addEsPackageJson() {

const packageJsonPath = path.join(
path.dirname(file),
vxPath.PACKAGE_JSON
opts.fileNames.PACKAGE_JSON
);

if (fse.existsSync(packageJsonPath)) {
Expand Down
10 changes: 7 additions & 3 deletions vx/config/rollup/plugins/handleExports.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,13 @@ function writePackageJson(name, exportPath, { namespace } = {}) {
pkgJson = { ...packageJson(name), ...pkgJson };
}

fse.writeJSONSync(joinPath(exportPath, vxPath.PACKAGE_JSON), pkgJson, {
spaces: 2,
});
fse.writeJSONSync(
joinPath(exportPath, opts.fileNames.PACKAGE_JSON),
pkgJson,
{
spaces: 2,
}
);
}

function generatePackageJson(moduleName, namespace) {
Expand Down
2 changes: 2 additions & 0 deletions vx/opts.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ module.exports = {
JEST_SETUP: 'jest.setup.ts',
JEST_SETUP_AFTER_ENV: 'jest.setupAfterEnv.ts',
MAIN_EXPORT: 'index.js',
PACKAGE_JSON: 'package.json',
TSCONFIG_JSON: 'tsconfig.json',
VX_BUILD: 'vx.build.js',
},
format: {
Expand Down
6 changes: 5 additions & 1 deletion vx/packageNames.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const path = require('path');

const glob = require('glob');

const opts = require('vx/opts');
const { usePackage } = require('vx/vxContext');
const vxPath = require('vx/vxPath');

Expand All @@ -16,7 +17,10 @@ module.exports = Object.defineProperty(
);

const paths = glob.sync(vxPath.package('*')).filter(packagePath => {
const packageJson = require(path.resolve(packagePath, vxPath.PACKAGE_JSON));
const packageJson = require(path.resolve(
packagePath,
opts.fileNames.PACKAGE_JSON
));

return !packageJson.private;
});
Expand Down
5 changes: 2 additions & 3 deletions vx/scripts/genTsConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const lodash = require('lodash');

const exec = require('vx/exec');
const logger = require('vx/logger');
const opts = require('vx/opts');
const getModuleAliases = require('vx/util/moduleAliases');
const vxPath = require('vx/vxPath');

Expand Down Expand Up @@ -56,7 +55,7 @@ function tsConfigTemplate() {
sourceMap: true,
strict: true,
},
files: [`./${opts.dir.CONFIG}/jest/globals.d.ts`],
include: [`./${opts.dir.PACKAGES}/*/${opts.dir.SRC}/**/*.ts`],
files: [`${vxPath.rel(vxPath.JEST_CONFIG_PATH)}/globals.d.ts`],
include: [vxPath.rel(vxPath.packageSrc('*', '**/*.ts'))],
};
}
6 changes: 3 additions & 3 deletions vx/util/moduleAliases.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ const glob = require('glob');
const opts = require('vx/opts');
const vxPath = require('vx/vxPath');

const matches = glob.sync(`./${opts.dir.PACKAGES}/*/${opts.dir.SRC}/**/*.ts`, {
const matches = glob.sync(vxPath.rel(vxPath.packageSrc('*', '**/*.ts')), {
cwd: vxPath.ROOT_PATH,
absolute: false,
ignore: [
`./${opts.dir.PACKAGES}/*/${opts.dir.SRC}/**/index.ts`,
`./${opts.dir.PACKAGES}/*/${opts.dir.SRC}/**/${opts.dir.TESTS}/**/*`,
vxPath.rel(vxPath.packageSrc('*', '**/*/index.ts')),
vxPath.rel(vxPath.packageSrc('*', `**/${opts.dir.TESTS}/**/*`)),
],
});

Expand Down
3 changes: 2 additions & 1 deletion vx/util/rootPackageJson.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
const fs = require('fs');
const path = require('path');

const opts = require('vx/opts');
const vxPath = require('vx/vxPath');

function rootPackageJson() {
// Manually reading it instead of requiring to avoid caching
const jsonString = fs.readFileSync(
path.join(vxPath.ROOT_PATH, vxPath.PACKAGE_JSON),
path.join(vxPath.ROOT_PATH, opts.fileNames.PACKAGE_JSON),
'utf8'
);
return JSON.parse(jsonString);
Expand Down
20 changes: 11 additions & 9 deletions vx/vxPath.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,11 @@ const { usePackage } = require('vx/vxContext');

const vxPath = {};

const PACKAGE_JSON = 'package.json';
const TSCONFIG_JSON = 'tsconfig.json';
const VX = 'vx';

vxPath.PACKAGE_JSON = PACKAGE_JSON;
vxPath.TSCONFIG_JSON = TSCONFIG_JSON;

vxPath.vxRoot = () => {
return vxPath.closest(process.cwd(), (current, breakout) => {
const pkgJsonPath = path.resolve(current, PACKAGE_JSON);
const pkgJsonPath = path.resolve(current, opts.fileNames.PACKAGE_JSON);

if (!fs.existsSync(pkgJsonPath)) {
return;
Expand Down Expand Up @@ -50,11 +45,11 @@ vxPath.packageSrcExports = (pkgName = usePackage(), ...args) => {
};

vxPath.packageTsConfig = (pkgName = usePackage()) => {
return vxPath.package(pkgName, TSCONFIG_JSON);
return vxPath.package(pkgName, opts.fileNames.TSCONFIG_JSON);
};

vxPath.packageJson = (pkgName = usePackage()) => {
return vxPath.package(pkgName, PACKAGE_JSON);
return vxPath.package(pkgName, opts.fileNames.PACKAGE_JSON);
};

vxPath.closest = (start, predicate) => {
Expand Down Expand Up @@ -82,6 +77,10 @@ vxPath.closest = (start, predicate) => {
}
};

vxPath.rel = absolutePath => {
return ['.', path.relative(vxPath.ROOT_PATH, absolutePath)].join(path.sep);
};

vxPath.ROOT_PATH = vxPath.vxRoot();

vxPath.VX_ROOT_PATH = path.resolve(vxPath.ROOT_PATH, VX);
Expand All @@ -103,7 +102,10 @@ vxPath.JEST_CONFIG_FILE_PATH = path.resolve(
opts.fileNames.JEST_CONFIG
);

vxPath.TSCONFIG_PATH = path.resolve(vxPath.ROOT_PATH, TSCONFIG_JSON);
vxPath.TSCONFIG_PATH = path.resolve(
vxPath.ROOT_PATH,
opts.fileNames.TSCONFIG_JSON
);

vxPath.PACKAGES_PATH = path.resolve(vxPath.ROOT_PATH, opts.dir.PACKAGES);

Expand Down

1 comment on commit b99e817

@vercel
Copy link

@vercel vercel bot commented on b99e817 Apr 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

vest-next – ./website

vest-next.vercel.app
vest-next-git-latest-ealush.vercel.app
vest-next-ealush.vercel.app
vest-website.vercel.app

Please sign in to comment.