Skip to content

Commit

Permalink
Use ocular-build to build dev-tools (#451)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pessimistress authored Feb 21, 2024
1 parent 600114f commit cdff7b9
Show file tree
Hide file tree
Showing 44 changed files with 228 additions and 202 deletions.
18 changes: 18 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,24 @@ module.exports = getESLintConfig({
node: true
},

overrides: [
{
// may use aliases/dev dependencies
files: [
'**/test/**/*.js',
'**/test/**/*.ts'
],
globals: {
process: true
},
rules: {
'import/no-unresolved': 0,
'import/no-extraneous-dependencies': 0,
'no-process-env': 0
}
}
],

ignorePatterns: ['modules/gatsby-theme-ocular']
}
});
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ website-test/*
modules/dev-tools/.alias.json
coverage/
.nyc_output/
tsconfig.tsbuildinfo
2 changes: 1 addition & 1 deletion .ocularrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {resolve} from 'path';
/** @type {OcularConfig} */
let ocularConfig = {
typescript: {
check: true
project: 'tsconfig.json'
},

babel: false,
Expand Down
24 changes: 18 additions & 6 deletions modules/dev-tools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,26 @@
"src",
"scripts",
"templates",
"ts-plugins",
"dist",
"CHANGELOG.md"
],
"exports": {
".": "./src/index.js",
"./configuration": "./src/configuration/index.cjs",
"./ts-transform-version-inline": "./ts-plugins/ts-transform-version-inline/index.cjs",
"./ts-transform-append-extension": "./ts-plugins/ts-transform-append-extension/index.cjs"
".": {
"require": "./dist/index.cjs",
"import": "./src/index.js"
},
"./configuration": {
"require": "./dist/configuration/index.cjs",
"import": "./src/configuration/index.js"
},
"./ts-transform-version-inline": {
"require": "./dist/ts-plugins/ts-transform-version-inline/index.cjs",
"import": "./dist/ts-plugins/ts-transform-version-inline/index.js"
},
"./ts-transform-append-extension": {
"require": "./dist/ts-plugins/ts-transform-append-extension/index.cjs",
"import": "./dist/ts-plugins/ts-transform-append-extension/index.js"
}
},
"types": "./src/index.d.ts",
"main": "./src/index.js",
Expand All @@ -40,7 +52,7 @@
"scripts": {
"bootstrap": "yarn install-fast && ocular-bootstrap",
"clean": "echo No build needed",
"build": "tsc && find ./ts-plugins -depth -name \"*.js\" -exec sh -c 'f=\"{}\"; mv -- \"$f\" \"${f%.js}.cjs\"' \\;",
"build": "(cd ../.. && ocular-build)",
"lint": "npm run lint-yarn",
"lint-yarn": "!(grep -q unpm.u yarn.lock) || (echo 'Please rebuild yarn file using public npmrc' && false)",
"publish-prod": "npm run build && npm run test && npm run test dist && npm publish",
Expand Down
2 changes: 1 addition & 1 deletion modules/dev-tools/scripts/bootstrap.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env node

import {execShellCommand} from '../src/utils/shell.js';
import {execShellCommand} from './shell.js';
import {join} from 'path';

const scriptDir = new URL(import.meta.url).pathname;
Expand Down
2 changes: 1 addition & 1 deletion modules/dev-tools/scripts/build.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env node

import {execShellCommand} from '../src/utils/shell.js';
import {execShellCommand} from './shell.js';
import {join} from 'path';

const scriptDir = new URL(import.meta.url).pathname;
Expand Down
12 changes: 6 additions & 6 deletions modules/dev-tools/scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
set -e

DEV_TOOLS_DIR=$(dirname $0)/..
CONFIG=`node $DEV_TOOLS_DIR/src/helpers/get-config.js ".babel.configPath"`
MODULES=`node $DEV_TOOLS_DIR/src/helpers/get-config.js ".modules" | sed -E "s/,/ /g"`
EXTENSIONS=`node $DEV_TOOLS_DIR/src/helpers/get-config.js ".babel.extensions"`
TS_PROJECT=`node $DEV_TOOLS_DIR/src/helpers/get-config.js ".typescript.project"`
IS_ESM=`node $DEV_TOOLS_DIR/src/helpers/get-config.js ".esm"`
CONFIG=`ts-node $DEV_TOOLS_DIR/src/helpers/get-config.js ".babel.configPath"`
MODULES=`ts-node $DEV_TOOLS_DIR/src/helpers/get-config.js ".modules" | sed -E "s/,/ /g"`
EXTENSIONS=`ts-node $DEV_TOOLS_DIR/src/helpers/get-config.js ".babel.extensions"`
TS_PROJECT=`ts-node $DEV_TOOLS_DIR/src/helpers/get-config.js ".typescript.project"`
IS_ESM=`ts-node $DEV_TOOLS_DIR/src/helpers/get-config.js ".esm"`

check_target() {
if [[ ! "$1" =~ ^es5|esm ]]; then
Expand All @@ -28,7 +28,7 @@ build_src() {

build_module_esm() {
build_src dist esm-strict
node $DEV_TOOLS_DIR/src/build-cjs.js
ts-node $DEV_TOOLS_DIR/src/build-cjs.js
}

build_module() {
Expand Down
2 changes: 1 addition & 1 deletion modules/dev-tools/scripts/bundle.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env node

import esbuild from 'esbuild';
import {getBundleConfig} from '../src/configuration/get-esbuild-config.js';
import {getBundleConfig} from '../dist/configuration/get-esbuild-config.js';

// Parse command line arguments
let entryPoint;
Expand Down
2 changes: 1 addition & 1 deletion modules/dev-tools/scripts/clean.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env node

import {execShellCommand} from '../src/utils/shell.js';
import {execShellCommand} from './shell.js';
import {join} from 'path';

const scriptDir = new URL(import.meta.url).pathname;
Expand Down
2 changes: 1 addition & 1 deletion modules/dev-tools/scripts/lint.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env node

import {execShellCommand} from '../src/utils/shell.js';
import {execShellCommand} from './shell.js';
import {join} from 'path';

const scriptDir = new URL(import.meta.url).pathname;
Expand Down
4 changes: 2 additions & 2 deletions modules/dev-tools/scripts/lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ MODE=$1

DEV_TOOLS_DIR=$(dirname $0)/..

DIRECTORIES=`node $DEV_TOOLS_DIR/src/helpers/get-config.js ".lint.paths"`
DIRECTORIES=`ts-node $DEV_TOOLS_DIR/src/helpers/get-config.js ".lint.paths"`
if [[ $DIRECTORIES == *","* ]]; then
DIRECTORIES={$DIRECTORIES}
fi

EXTENSIONS=`node $DEV_TOOLS_DIR/src/helpers/get-config.js ".lint.extensions"`
EXTENSIONS=`ts-node $DEV_TOOLS_DIR/src/helpers/get-config.js ".lint.extensions"`
if [[ $EXTENSIONS == *","* ]]; then
EXTENSIONS={$EXTENSIONS}
fi
Expand Down
2 changes: 1 addition & 1 deletion modules/dev-tools/scripts/metrics.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env node

import {execShellCommand} from '../src/utils/shell.js';
import {execShellCommand} from './shell.js';
import {join} from 'path';

const scriptDir = new URL(import.meta.url).pathname;
Expand Down
2 changes: 1 addition & 1 deletion modules/dev-tools/scripts/metrics.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ WORKING_DIR=`pwd`
TMP_DIR=$WORKING_DIR/tmp

# Get size metric entry point
ENTRY_POINTS=`node $DEV_TOOLS_DIR/src/helpers/get-config.js ".entry.size"`
ENTRY_POINTS=`ts-node $DEV_TOOLS_DIR/src/helpers/get-config.js ".entry.size"`
IFS=','
read -a ENTRY_POINTS_ARR <<< "$ENTRY_POINTS"
IFS=' '
Expand Down
2 changes: 1 addition & 1 deletion modules/dev-tools/scripts/publish.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env node

import {execShellCommand} from '../src/utils/shell.js';
import {execShellCommand} from './shell.js';
import {join} from 'path';

const scriptDir = new URL(import.meta.url).pathname;
Expand Down
11 changes: 11 additions & 0 deletions modules/dev-tools/scripts/shell.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import {execSync} from 'child_process';

export function execShellCommand(command, args = []) {
try {
execSync(`${command} ${args.join(' ')}`, {
stdio: 'inherit'
});
} catch (err) {
process.exit(err.status);
}
}
2 changes: 1 addition & 1 deletion modules/dev-tools/scripts/test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env node

import {execShellCommand} from '../src/utils/shell.js';
import {execShellCommand} from './shell.js';
import {join} from 'path';

const scriptDir = new URL(import.meta.url).pathname;
Expand Down
5 changes: 2 additions & 3 deletions modules/dev-tools/scripts/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ usage() {
}

run_test_script() {
(set -x; NODE_ENV=test node $TEST_SCRIPT $1)
(set -x; NODE_ENV=test ts-node $TEST_SCRIPT $1)
}

run_full_test() {
Expand Down Expand Up @@ -48,7 +48,7 @@ case $MODE in

"node-debug")
echo "Open chrome://inspect/#devices to attach debugger."
(set -x; node --inspect-brk $TEST_SCRIPT node)
(set -x; ts-node --inspect-brk $TEST_SCRIPT node)
;;

"dist")
Expand All @@ -57,7 +57,6 @@ case $MODE in

"cover")
run_test_script cover
# (set -x; npx c8 node $TEST_SCRIPT cover)
(set -x; npx c8 report --reporter=lcov)
;;

Expand Down
11 changes: 5 additions & 6 deletions modules/dev-tools/src/build-cjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,21 @@ import {getCJSEntryPoints} from './helpers/get-cjs-entry-points.js';
import {getCJSExportConfig} from './configuration/get-esbuild-config.js';

async function main() {
for (const fileName of getCJSEntryPoints()) {
const inputPath = `./dist/${fileName}.js`;
for (const entry of getCJSEntryPoints()) {
try {
await fs.stat(inputPath);
await fs.stat(entry.inputFile);

const esbuildConfig = await getCJSExportConfig({
input: inputPath,
output: `dist/${fileName}.cjs`
input: entry.inputFile,
output: entry.outputFile
});
const result = await esbuild.build(esbuildConfig);
if (result.errors.length > 0) {
process.exit(1);
}
} catch {
// File does not exist
console.error(`\x1b[33mCannot find file ${inputPath}\x1b[0m`);
console.error(`\x1b[33mCannot find file ${entry.inputFile}\x1b[0m`);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,21 @@
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

module.exports = {
extends: [
'./best-practices.json',
'./ecmascript-6.json',
'./miscellaneous.json',
'./stylistic-issues.json',
'../eslint-config-uber-es5/eslintrc.cjs'
{
"extends": [
"./best-practices.json",
"./ecmascript-6.json",
"./miscellaneous.json",
"./stylistic-issues.json",
"../eslint-config-uber-es5/eslintrc.json"
],
env: {
es6: true
"env": {
"es6": true
},
parserOptions: {
sourceType: 'module',
ecmaFeatures: {
experimentalObjectRestSpread: true
"parserOptions": {
"sourceType": "module",
"ecmaFeatures": {
"experimentalObjectRestSpread": true
}
}
};
}
Loading

0 comments on commit cdff7b9

Please sign in to comment.