@cmmn/tools 1.8.1 → 1.8.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import fs from "fs";
|
|
4
4
|
|
|
5
5
|
function visitExportNode(exportNode, sourceFile) {
|
|
6
6
|
if (exportNode.typeOnly){
|
|
@@ -27,6 +27,7 @@ function visitExportNode(exportNode, sourceFile) {
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
function visitImportNode(importNode, sourceFile, options, context) {
|
|
30
|
+
const factory = context.factory;
|
|
30
31
|
const file = importNode.moduleSpecifier?.text;
|
|
31
32
|
if (!file || !file.startsWith('.'))
|
|
32
33
|
return;
|
|
@@ -37,16 +38,16 @@ function visitImportNode(importNode, sourceFile, options, context) {
|
|
|
37
38
|
if (/\.(less|css|scss|sass|svg|png|html)$/.test(file)) {
|
|
38
39
|
const absSource = formatPath(path.join(options.outDir, formatPath(path.relative(options.baseUrl, sourceFileDir))));
|
|
39
40
|
const relFile = path.relative(absSource, abs).replaceAll(path.sep, '/');
|
|
40
|
-
return
|
|
41
|
+
return factory.updateImportDeclaration(importNode, importNode.decorators, importNode.modifiers, importNode.importClause, factory.createStringLiteral(relFile));
|
|
41
42
|
}
|
|
42
43
|
if (/\.(json|tsx?|jsx?)$/.test(file))
|
|
43
44
|
return;
|
|
44
45
|
if (fs.existsSync(abs + '.ts') || fs.existsSync(abs + '.tsx')) {
|
|
45
|
-
return
|
|
46
|
+
return factory.updateImportDeclaration(importNode, importNode.decorators, importNode.modifiers, importNode.importClause, factory.createStringLiteral(file + '.js'));
|
|
46
47
|
}
|
|
47
48
|
if (fs.existsSync(abs + '/')) {
|
|
48
49
|
const indexFile = `${file}/index.js`;
|
|
49
|
-
return
|
|
50
|
+
return factory.updateImportDeclaration(importNode, importNode.decorators, importNode.modifiers, importNode.importClause, factory.createStringLiteral(indexFile));
|
|
50
51
|
}
|
|
51
52
|
}
|
|
52
53
|
|
|
@@ -65,9 +66,8 @@ function visitRequireNode(importNode, sourceFile) {
|
|
|
65
66
|
}
|
|
66
67
|
}
|
|
67
68
|
|
|
68
|
-
const lessToStringTransformer = function (context) {
|
|
69
|
+
export const lessToStringTransformer = function (context) {
|
|
69
70
|
const options = context.getCompilerOptions();
|
|
70
|
-
console.log(context);
|
|
71
71
|
return (sourceFile) => {
|
|
72
72
|
function visitor(node) {
|
|
73
73
|
// if (node && node.kind == ts.SyntaxKind.ImportDeclaration) {
|
|
@@ -95,7 +95,4 @@ const lessToStringTransformer = function (context) {
|
|
|
95
95
|
|
|
96
96
|
return ts.visitEachChild(sourceFile, visitor, context);
|
|
97
97
|
};
|
|
98
|
-
};
|
|
99
|
-
exports.default = function (program, pluginOptions) {
|
|
100
|
-
return lessToStringTransformer;
|
|
101
|
-
}
|
|
98
|
+
};
|
package/compile/compile.js
CHANGED
|
@@ -1,11 +1,21 @@
|
|
|
1
1
|
import ts from "typescript/lib/typescript.js";
|
|
2
2
|
import {resolve, relative} from 'path';
|
|
3
3
|
import fs from "fs";
|
|
4
|
+
import { lessToStringTransformer } from "./absolute-plugin.js";
|
|
5
|
+
|
|
4
6
|
const rootDir = process.cwd();
|
|
5
7
|
|
|
6
8
|
export function compile(...flags) {
|
|
7
9
|
|
|
8
10
|
const host = ts.createSolutionBuilderWithWatchHost(ts.sys, createProgram);
|
|
11
|
+
console.log()
|
|
12
|
+
host.getCustomTransformers = () => ({
|
|
13
|
+
before: [
|
|
14
|
+
lessToStringTransformer
|
|
15
|
+
],
|
|
16
|
+
afterDeclarations: [
|
|
17
|
+
]
|
|
18
|
+
});
|
|
9
19
|
host.useCaseSensitiveFileNames();
|
|
10
20
|
|
|
11
21
|
const builderFactory = flags.includes('--watch') ?
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cmmn/tools",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.6",
|
|
4
4
|
"description": "Compilation, bundling, code generator, testing.",
|
|
5
5
|
"main": "dist/rollup.config.js",
|
|
6
6
|
"type": "module",
|
|
@@ -83,5 +83,5 @@
|
|
|
83
83
|
},
|
|
84
84
|
"author": "",
|
|
85
85
|
"license": "ISC",
|
|
86
|
-
"gitHead": "
|
|
86
|
+
"gitHead": "c49859634cc0fb40bc888d468d46f8b47b7ff840"
|
|
87
87
|
}
|