Skip to content
This repository was archived by the owner on Jul 10, 2025. It is now read-only.

Commit a7586eb

Browse files
committed
chore: intial commit
0 parents  commit a7586eb

21 files changed

+6584
-0
lines changed

.editorconfig

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
root = true
2+
3+
[*]
4+
indent_style = space
5+
indent_size = 2
6+
charset = utf-8
7+
trim_trailing_whitespace = true
8+
insert_final_newline = true
9+
10+
[*.md]
11+
trim_trailing_whitespace = false

.esbuildrc.js

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import EsbuildVue from 'esbuild-vue';
2+
import { esbuildPluginNodeExternals } from 'esbuild-plugin-node-externals';
3+
import DynamicImport from './esbuild-dynamic-import.js';
4+
5+
// Example working esbuild config I use in my companies codebase
6+
// reference at https://esbuild.github.io/api/#build-api
7+
export default {
8+
target: 'node16',
9+
format: 'esm',
10+
platform: 'node',
11+
mainFields: ['module', 'main', 'browser'],
12+
external: [
13+
'canvas',
14+
'worker-loader!pdfjs-dist/es5/build/pdf.worker.js',
15+
'pdfmake',
16+
'xlsx'
17+
],
18+
plugins: [
19+
/**
20+
* Transforms all dynamic imports that contain a template literal varable and
21+
* has an extension passed in by transformExtensions. I.E. import(`../../${file}.vue)
22+
* will be turned into static imports of every possible valid import it could be. It then
23+
* uses the static import reference in the file. Reason for this is we want esbuild
24+
* to process the possible imports that are .vue (SFC vue) files so they can be
25+
* processed by the EsbuildVue plugin and made into valid javascript that nodejs can run.
26+
*
27+
* Also with this plugin is that if there exists a dynamic import like I.E. import(`../../$file}.js`)
28+
* that could be resolved at runtime just fine by nodejs, but the only issue is that the relative
29+
* file path is now different due to the bundled file produced by esbuild being in likely differnt
30+
* file location. changeRelativeToAbsolute will fix this issue by changing all relative imports to
31+
* absolute ones. I will also note that the dynamic import in my project needs to be relative due
32+
* to also using vite for production builds which uses rollup internally.
33+
* Rollup requires all dynamic imports be relative, so I can't just use process.cwd() in the source code.
34+
*/
35+
DynamicImport({ transformExtensions: ['.vue'], changeRelativeToAbsolute: true }),
36+
// Current plugin is for Vue 2 SFC https://www.npmjs.com/package/esbuild-vue
37+
// for Vue 3 SFC https://www.npmjs.com/package/esbuild-plugin-vue3
38+
EsbuildVue(),
39+
// since we are running tests inde nodejs only include the packages that need
40+
// to be processed by esbuild for whatever reason. That way the bundled file
41+
// size can be decreased and defer to node at runtime to load the exclude packages
42+
// note including a package down below will likely pull in its dependencies also
43+
// For example vue-pdf was then pulling in pdfjs-dst work, I had to add that
44+
// to the externals array above to explicitly disallow bundling that in
45+
esbuildPluginNodeExternals({
46+
include: [
47+
'bootstrap-vue',
48+
'vue-typeahead-bootstrap',
49+
'vue-pdf',
50+
'vue-datetime',
51+
'@amcharts/amcharts4',
52+
'rtvision-app-common',
53+
'ajv',
54+
'ol-layerswitcher',
55+
'@vue/composition-api',
56+
'ol',
57+
'@shopify/draggable'
58+
]
59+
})
60+
],
61+
define: {
62+
'process.env.NODE_ENV': JSON.stringify('development'),
63+
'process.env.TEST_ENV': JSON.stringify(true)
64+
}
65+
}

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/lib

.eslintrc.json

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
{
2+
"parserOptions": {
3+
"parser": "@typescript-eslint/parser"
4+
},
5+
"extends": [
6+
"standard",
7+
"plugin:@typescript-eslint/eslint-recommended",
8+
"plugin:@typescript-eslint/recommended"
9+
],
10+
"plugins": [
11+
"@typescript-eslint"
12+
],
13+
"rules": {
14+
"accessor-pairs": "error",
15+
"arrow-spacing": ["error", { "before": true, "after": true }],
16+
"block-spacing": ["error", "always"],
17+
"brace-style": ["error", "1tbs", { "allowSingleLine": true }],
18+
"camelcase": ["error", { "properties": "never" }],
19+
"comma-dangle": ["error", {
20+
"arrays": "never",
21+
"objects": "never",
22+
"imports": "never",
23+
"exports": "never",
24+
"functions": "never"
25+
}],
26+
"comma-spacing": ["error", { "before": false, "after": true }],
27+
"comma-style": ["error", "last"],
28+
"constructor-super": "error",
29+
"curly": ["error", "multi-line"],
30+
"dot-location": ["error", "property"],
31+
"eol-last": "error",
32+
"eqeqeq": ["error", "always", { "null": "ignore" }],
33+
"func-call-spacing": ["error", "never"],
34+
"generator-star-spacing": ["error", { "before": true, "after": true }],
35+
"handle-callback-err": ["error", "^(err|error)$" ],
36+
"indent": ["error", "tab", { "SwitchCase": 1 }],
37+
"key-spacing": ["error", { "beforeColon": false, "afterColon": true }],
38+
"keyword-spacing": ["error", { "before": true, "after": true }],
39+
"new-cap": ["error", { "newIsCap": true, "capIsNew": false }],
40+
"new-parens": "error",
41+
"no-array-constructor": "error",
42+
"no-caller": "error",
43+
"no-class-assign": "error",
44+
"no-compare-neg-zero": "error",
45+
"no-cond-assign": "error",
46+
"no-const-assign": "error",
47+
"no-constant-condition": [1, { "checkLoops": false }],
48+
"no-control-regex": "error",
49+
"no-debugger": "error",
50+
"no-delete-var": "error",
51+
"no-dupe-args": "error",
52+
"no-dupe-class-members": "error",
53+
"no-dupe-keys": "error",
54+
"no-duplicate-case": "error",
55+
"no-empty-character-class": "error",
56+
"no-empty-pattern": "error",
57+
"no-ex-assign": "error",
58+
"no-extend-native": ["error", { "exceptions": ["String"] }],
59+
"no-extra-bind": "error",
60+
"no-extra-boolean-cast": "error",
61+
"no-extra-parens": ["error", "functions"],
62+
"no-fallthrough": "error",
63+
"no-floating-decimal": "error",
64+
"no-func-assign": "error",
65+
"no-global-assign": "error",
66+
"no-implied-eval": "error",
67+
"no-inner-declarations": ["error", "functions"],
68+
"no-invalid-regexp": "error",
69+
"no-irregular-whitespace": "error",
70+
"no-iterator": "error",
71+
"no-label-var": "error",
72+
"no-labels": ["error", { "allowLoop": false, "allowSwitch": false }],
73+
"no-lone-blocks": "error",
74+
"no-mixed-operators": ["error", {
75+
"groups": [
76+
["==", "!=", "===", "!==", ">", ">=", "<", "<="],
77+
["&&", "||"],
78+
["in", "instanceof"]
79+
],
80+
"allowSamePrecedence": true
81+
}],
82+
"no-mixed-spaces-and-tabs": "error",
83+
"no-multi-spaces": "error",
84+
"no-multi-str": "error",
85+
"no-multiple-empty-lines": ["error", { "max": 1, "maxEOF": 0 }],
86+
"no-negated-in-lhs": "error",
87+
"no-new": "error",
88+
"no-new-func": "error",
89+
"no-new-object": "error",
90+
"no-new-require": "error",
91+
"no-new-symbol": "error",
92+
"no-new-wrappers": "error",
93+
"no-obj-calls": "error",
94+
"no-octal": "error",
95+
"no-octal-escape": "error",
96+
"no-path-concat": "error",
97+
"no-proto": "error",
98+
"no-redeclare": "error",
99+
"no-regex-spaces": "error",
100+
"no-return-assign": ["error", "except-parens"],
101+
"no-return-await": "error",
102+
"no-self-assign": "error",
103+
"no-self-compare": "error",
104+
"no-sequences": "error",
105+
"no-shadow-restricted-names": "error",
106+
"no-sparse-arrays": "error",
107+
"no-template-curly-in-string": "error",
108+
"no-this-before-super": "error",
109+
"no-throw-literal": "error",
110+
"no-trailing-spaces": "error",
111+
"no-undef": "error",
112+
"no-undef-init": "error",
113+
"no-unmodified-loop-condition": "error",
114+
"no-unneeded-ternary": ["error", { "defaultAssignment": false }],
115+
"no-unreachable": "error",
116+
"no-unsafe-finally": "error",
117+
"no-unsafe-negation": "error",
118+
"no-unused-expressions": ["error", { "allowShortCircuit": true, "allowTernary": true, "allowTaggedTemplates": true }],
119+
"no-unused-vars": [1, { "vars": "all", "args": "none", "ignoreRestSiblings": true }],
120+
"no-use-before-define": ["error", { "functions": false, "classes": false, "variables": false }],
121+
"no-useless-call": "error",
122+
"no-useless-computed-key": "error",
123+
"no-useless-constructor": "error",
124+
"no-useless-escape": "error",
125+
"no-useless-rename": "error",
126+
"no-useless-return": "error",
127+
"no-whitespace-before-property": "error",
128+
"no-with": "error",
129+
"no-tabs": 0,
130+
"no-prototype-builtins": 0,
131+
"object-property-newline": ["error", { "allowMultiplePropertiesPerLine": true }],
132+
"one-var": ["error", { "initialized": "never" }],
133+
"operator-linebreak": ["error", "after", { "overrides": { "?": "before", ":": "before" } }],
134+
"padded-blocks": ["error", { "blocks": "never", "switches": "never", "classes": "never" }],
135+
"prefer-promise-reject-errors": "error",
136+
"quotes": ["error", "single", { "avoidEscape": true, "allowTemplateLiterals": true }],
137+
"rest-spread-spacing": ["error", "never"],
138+
"semi": [1, "always"],
139+
"semi-spacing": ["error", { "before": false, "after": true }],
140+
"space-before-blocks": ["error", "always"],
141+
"space-before-function-paren": ["error", "always"],
142+
"space-in-parens": ["error", "never"],
143+
"space-infix-ops": "error",
144+
"space-unary-ops": ["error", { "words": true, "nonwords": false }],
145+
"spaced-comment": [1, "always", {
146+
"line": { "markers": ["*package", "!", "/", ",", "="] },
147+
"block": { "balanced": true, "markers": ["*package", "!", ",", ":", "::", "flow-include"], "exceptions": ["*"] }
148+
}],
149+
"symbol-description": "error",
150+
"template-curly-spacing": ["error", "never"],
151+
"template-tag-spacing": ["error", "never"],
152+
"unicode-bom": ["error", "never"],
153+
"use-isnan": "error",
154+
"valid-typeof": ["error", { "requireStringLiterals": true }],
155+
"wrap-iife": ["error", "any", { "functionPrototypeMethods": true }],
156+
"yield-star-spacing": ["error", "both"],
157+
"yoda": ["error", "never"],
158+
"import/export": "error",
159+
"import/first": "error",
160+
"import/no-duplicates": "error",
161+
"import/no-webpack-loader-syntax": "error",
162+
"node/no-deprecated-api": "error",
163+
"node/process-exit-as-throw": "error",
164+
"promise/param-names": "error"
165+
}
166+
}

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
*-debug.log
2+
*-error.log
3+
/.nyc_output
4+
/dist
5+
/lib
6+
/tmp
7+
/yarn.lock
8+
node_modules

README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
mocha-esbuild
2+
=============
3+
4+
Run tests with mocha compiled by esbuild
5+
6+
[![oclif](https://img.shields.io/badge/cli-oclif-brightgreen.svg)](https://oclif.io)
7+
[![Version](https://img.shields.io/npm/v/mocha-esbuild.svg)](https://npmjs.org/package/mocha-esbuild)
8+
[![Downloads/week](https://img.shields.io/npm/dw/mocha-esbuild.svg)](https://npmjs.org/package/mocha-esbuild)
9+
[![License](https://img.shields.io/npm/l/mocha-esbuild.svg)](https://github.com/RtVision/mocha-esbuild/blob/master/package.json)
10+
11+
<!-- toc -->
12+
* [Usage](#usage)
13+
* [Commands](#commands)
14+
<!-- tocstop -->
15+
# Usage
16+
<!-- usage -->
17+
```sh-session
18+
$ npm install -g mocha-esbuild
19+
$ mocha-esbuild COMMAND
20+
running command...
21+
$ mocha-esbuild (-v|--version|version)
22+
mocha-esbuild/0.0.0 linux-x64 node-v16.10.0
23+
$ mocha-esbuild --help [COMMAND]
24+
USAGE
25+
$ mocha-esbuild COMMAND
26+
...
27+
```
28+
<!-- usagestop -->
29+
# Commands
30+
<!-- commands -->
31+
32+
<!-- commandsstop -->

bin/run

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env node
2+
3+
const fs = require('fs')
4+
const path = require('path')
5+
const project = path.join(__dirname, '../tsconfig.json')
6+
const dev = fs.existsSync(project)
7+
8+
if (dev) {
9+
require('ts-node').register({project})
10+
}
11+
12+
require(`../${dev ? 'src' : 'lib'}`).run()
13+
.catch(require('@oclif/errors/handle'))

bin/run.cmd

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@echo off
2+
3+
node "%~dp0\run" %*

0 commit comments

Comments
 (0)