Skip to content

Commit acc0eb5

Browse files
authored
Merge pull request #50 from scssyworks/0.0.x
0.0.x
2 parents 5ff429d + c060979 commit acc0eb5

36 files changed

+1096
-623
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
dist
22
node_modules
3-
.DS_Store
3+
.DS_Store
4+
coverage
5+
temp

.vscode/launch.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"type": "node",
9+
"request": "launch",
10+
"name": "JEST debug",
11+
"skipFiles": [
12+
"<node_internals>/**"
13+
],
14+
"runtimeExecutable": "npm",
15+
"runtimeArgs": [
16+
"run-script",
17+
"test",
18+
"--",
19+
"${relativeFile}"
20+
]
21+
}
22+
]
23+
}

ROADMAP.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
- [x] Add support for `init` command to add configuration files in workspace
66
- [x] Add support for `lint` command to lint files in workspace
77
- [ ] Add support for `test` command to test files in workspace
8-
- [ ] Add support for `SWC` compilation for faster builds
8+
- [x] Add support for `SWC` compilation for faster builds
99
- [ ] Add support for `CSS`, `SCSS`, `CSS modules` and `SCSS modules`
1010
- [x] Add support for `JSON` files
11-
- [ ] Add support for `yaml` and `graphql` files
11+
- [x] Add support for `yaml` and `graphql` files
1212
- [ ] Add support for `tailwindcss`
1313
- [ ] Add support for `CSS-in-JS` libraries
1414
- [ ] Add support for `--watch`

bin/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ const addCommonOptions = (yargs) =>
3030
type: 'string',
3131
describe: 'Provide custom rollup configuration',
3232
alias: 'c',
33+
})
34+
.option('swc', {
35+
...boolConfig,
36+
describe: 'Switch to SWC compiler',
3337
});
3438

3539
yargs(hideBin(process.argv))

bin/rollup-scripts/init/index.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const path = require('node:path');
44
const rsConfig = require('../../../templates/rs.json');
55
const babelConfig = require('../../../templates/babel.config');
66
const eslintConfig = require('../../../templates/eslint.config');
7+
const swcConfig = require('../../../templates/swc.config');
78
const {
89
MSG_CONFIG,
910
MSG_CONFIGBABEL,
@@ -12,6 +13,7 @@ const {
1213
configFiles,
1314
MSG_CONFIGESLINT,
1415
MSG_INIT,
16+
MSG_CONFIGSWC,
1517
} = require('../../../constants');
1618
const {
1719
resolvePath,
@@ -28,6 +30,8 @@ async function getConfig(configType, args) {
2830
return babelConfig(args);
2931
case configTypes.ESLINT:
3032
return await eslintConfig(args);
33+
case configTypes.SWC:
34+
return swcConfig(args);
3135
}
3236
}
3337

@@ -37,12 +41,14 @@ function getMessage(configType) {
3741
return MSG_CONFIGBABEL;
3842
case configTypes.ESLINT:
3943
return MSG_CONFIGESLINT;
44+
case configTypes.SWC:
45+
return MSG_CONFIGSWC;
4046
}
4147
}
4248

4349
async function generateConfig(args, configType, configFile) {
4450
const logger = getLogger(args);
45-
const hasConfig = await check(configType);
51+
const hasConfig = check(configType);
4652
if (!hasConfig) {
4753
const conf = await getConfig(configType, args);
4854
await fsPromises.writeFile(
@@ -55,7 +61,7 @@ async function generateConfig(args, configType, configFile) {
5561
}
5662

5763
module.exports = async function init(args) {
58-
const { configFile } = args;
64+
const { configFile, swc } = args;
5965
const logger = getLogger(args);
6066
const { src, sourceTypes } = getInputProps(args, logger);
6167
const finalArgs = updateArgs(args, sourceTypes);
@@ -76,6 +82,9 @@ module.exports = async function init(args) {
7682
}
7783
await generateConfig(finalArgs, configTypes.BABEL, configFiles.BABEL);
7884
await generateConfig(finalArgs, configTypes.ESLINT, configFiles.ESLINT);
85+
if (swc) {
86+
await generateConfig(finalArgs, configTypes.SWC, configFiles.SWC);
87+
}
7988
} catch (e) {
8089
logger.verbose(e);
8190
}

bin/rollup-scripts/lint/index.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const {
1313
MSG_LINT,
1414
MSG_LINTED,
1515
MSG_LINTER,
16+
ERR_SWC_ESLINT,
1617
} = require('../../../constants');
1718

1819
module.exports = async function lint(args) {
@@ -22,15 +23,17 @@ module.exports = async function lint(args) {
2223
const finalArgs = updateArgs(args, sourceTypes);
2324
logger.log(MSG_LINT);
2425
logger.timeStart(MSG_LINTED);
25-
const eslintConfigFile = await check(configTypes.ESLINT);
26-
const { fix, formatter: formatterType } = finalArgs;
26+
const { fix, formatter: formatterType, swc } = finalArgs;
2727
try {
28+
if (swc) {
29+
logger.warn(ERR_SWC_ESLINT);
30+
}
2831
let errorCount = 0;
2932
let warningCount = 0;
3033
let totalFiles = 0;
3134
const overrideConfig = await eslintConfig(finalArgs);
3235
const eslint = new ESLint({
33-
useEslintrc: !!eslintConfigFile,
36+
useEslintrc: Boolean(check(configTypes.ESLINT)),
3437
overrideConfig,
3538
fix,
3639
});
@@ -42,15 +45,19 @@ module.exports = async function lint(args) {
4245
});
4346
const formatter = await eslint.loadFormatter(formatterType);
4447
const resultText = formatter.format(results);
48+
let hasErrors = false;
4549
if (errorCount > 0) {
4650
logger.error(MSG_LINTER(totalFiles, errorCount, warningCount));
51+
hasErrors = true;
4752
} else if (warningCount > 0) {
4853
logger.warn(MSG_LINTER(totalFiles, errorCount, warningCount));
4954
} else {
5055
logger.success(MSG_LINTER(totalFiles, errorCount, warningCount));
5156
}
52-
5357
console.log(resultText);
58+
if (hasErrors) {
59+
throw new Error(''); // Throwing error to exit process with error code
60+
}
5461
} catch (e) {
5562
logger.verbose(e);
5663
process.exit(1);

constants/index.js

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@ const DEFAULT_ENCODING = {
1414
const configTypes = {
1515
BABEL: 'babel',
1616
ESLINT: 'eslintConfig',
17+
SWC: 'swc',
1718
};
1819

1920
const configFiles = {
2021
BABEL: '.babelrc',
2122
ESLINT: '.eslintrc.json',
23+
SWC: '.swcrc',
2224
};
2325

2426
const JSX_MODULES = ['react', 'preact'];
@@ -35,18 +37,28 @@ const VAR_FILE_PATH = '$$filePath$$';
3537

3638
const DEV = /\.development/;
3739

38-
const SUPPORTED_BABEL_FILES = [
39-
/^babel\.config\.(j|mj|cj|ct)s$/,
40-
/^babel\.config\.json$/,
41-
/^\.babelrc\.(j|mj|cj|ct)s$/,
42-
/^\.babelrc\.json$/,
43-
/^\.babelrc$/,
40+
const VALID_BABEL_FILES = [
41+
'babel.config.js',
42+
'babel.config.ts',
43+
'babel.config.mjs',
44+
'babel.config.cjs',
45+
'babel.config.cts',
46+
'babel.config.json',
47+
'.babelrc',
48+
'.babelrc.js',
49+
'.babelrc.ts',
50+
'.babelrc.mjs',
51+
'.babelrc.cjs',
52+
'.babelrc.cts',
53+
'.babelrc.json',
4454
];
4555

46-
const SUPPORTED_ESLINT_CONFIG_FILES = [
47-
/^\.eslintrc\.(j|cj)s$/,
48-
/^\.eslintrc\.(y|ya)ml$/,
49-
/^\.eslintrc\.json$/,
56+
const VALID_ESLINTCONFIG_FILES = [
57+
'.eslintrc.js',
58+
'.eslintrc.cjs',
59+
'.eslintrc.yml',
60+
'.eslintrc.yaml',
61+
'.eslintrc.json',
5062
];
5163

5264
const MSG_INIT = 'Initializing...';
@@ -57,15 +69,18 @@ const MSG_LINTED = 'Completed in';
5769
const MSG_LINTER = (totalFiles, errorCount, warningCount) =>
5870
`Checked ${totalFiles} files! Found ${errorCount} errors and ${warningCount} warnings.`;
5971
const MSG_EMITTED = 'Emitted:';
60-
const MSG_BABELRC = 'Using babel config from workspace';
72+
const MSG_BABELRC = 'Using babel from workspace';
6173
const MSG_CONFIG = (filename) => `${PREFIX}${filename}`;
6274
const MSG_CONFIGBABEL = `${PREFIX}.babelrc`;
6375
const MSG_CONFIGESLINT = `${PREFIX}.eslintrc.json`;
76+
const MSG_CONFIGSWC = `${PREFIX}.swcrc`;
6477
const ERR_NOTFOUND = 'File not found!';
6578
const ERR_ENTRYFILE =
6679
'Warning: Input file could not be resolved. Using "index.mjs" as default. Run the following command to configure "input" if you feel this is not right:';
6780
const ERR_SILENT_VERBOSE =
6881
'Warning: "--verbose" is currently enabled. "--silent" will be ignored!';
82+
const ERR_SWC_ESLINT =
83+
'Eslint currently does not support SWC. Switching to Babel instead.';
6984
const CMD_INIT = `npx ${SCRIPT_NAME} init`;
7085
const ERR_JSX_MODULE = (modules) =>
7186
`More than one JSX runtime detected ==> ${modules.join(', ')}`;
@@ -87,8 +102,6 @@ const ESLINT_REACT_EXTENSIONS = [
87102
'plugin:react-hooks/recommended',
88103
];
89104

90-
const ESLINT_PREACT_EXTENSIONS = ['preact'];
91-
92105
module.exports = {
93106
DEV,
94107
ROOT,
@@ -102,15 +115,15 @@ module.exports = {
102115
ERR_NOTFOUND,
103116
ERR_ENTRYFILE,
104117
ERR_SILENT_VERBOSE,
105-
SUPPORTED_BABEL_FILES,
106-
SUPPORTED_ESLINT_CONFIG_FILES,
118+
ERR_SWC_ESLINT,
107119
MSG_EMITTED,
108120
MSG_COMPILE,
109121
MSG_COMPILED,
110122
MSG_BABELRC,
111123
MSG_CONFIG,
112124
MSG_CONFIGBABEL,
113125
MSG_CONFIGESLINT,
126+
MSG_CONFIGSWC,
114127
MSG_LINT,
115128
MSG_LINTED,
116129
MSG_LINTER,
@@ -125,5 +138,6 @@ module.exports = {
125138
ESLINT_DEFAULT_EXTENSIONS,
126139
ESLINT_TYPSCRIPT_EXTENSIONS,
127140
ESLINT_REACT_EXTENSIONS,
128-
ESLINT_PREACT_EXTENSIONS,
141+
VALID_BABEL_FILES,
142+
VALID_ESLINTCONFIG_FILES,
129143
};

0 commit comments

Comments
 (0)