Skip to content

Commit 51cd876

Browse files
committed
commit dist to try and build from github
1 parent 06854f2 commit 51cd876

27 files changed

+835
-1
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/.vscode
22
/node_modules
33
/coverage
4-
/dist
54
npm-debug.log
65
yarn-error.log

dist/helpers/classTransforms.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import { ClassnameTransformOptions } from '../options';
2+
export declare const transformClasses: (camelCaseOption?: ClassnameTransformOptions) => (classname: string) => string[];

dist/helpers/classTransforms.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
"use strict";
2+
var __importDefault = (this && this.__importDefault) || function (mod) {
3+
return (mod && mod.__esModule) ? mod : { "default": mod };
4+
};
5+
Object.defineProperty(exports, "__esModule", { value: true });
6+
exports.transformClasses = void 0;
7+
var lodash_camelcase_1 = __importDefault(require("lodash.camelcase"));
8+
// The below is based on the CSS Modules implementation found here:
9+
// https://github.com/webpack-contrib/css-loader
10+
var dashCase = function (classname) {
11+
return classname.replace(/-+(\w)/g, function (_match, firstLetter) {
12+
return firstLetter.toUpperCase();
13+
});
14+
};
15+
var transformClasses = function (camelCaseOption) {
16+
return function (classname) {
17+
var entries = [];
18+
switch (camelCaseOption) {
19+
case 'camelCase': {
20+
entries.push(classname);
21+
var targetClassName = (0, lodash_camelcase_1.default)(classname);
22+
if (targetClassName !== classname) {
23+
entries.push(targetClassName);
24+
}
25+
break;
26+
}
27+
case 'camelCaseOnly':
28+
entries.push((0, lodash_camelcase_1.default)(classname));
29+
break;
30+
case 'dashes': {
31+
entries.push(classname);
32+
var targetClassName = dashCase(classname);
33+
if (targetClassName !== classname) {
34+
entries.push(targetClassName);
35+
}
36+
break;
37+
}
38+
case 'dashesOnly':
39+
entries.push(dashCase(classname));
40+
break;
41+
case 'asIs':
42+
default:
43+
entries.push(classname);
44+
break;
45+
}
46+
return entries;
47+
};
48+
};
49+
exports.transformClasses = transformClasses;

dist/helpers/createDtsExports.d.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { Options } from '../options';
2+
import { CSSExportsWithSourceMap } from './getCssExports';
3+
import { Logger } from './logger';
4+
export declare const createDtsExports: ({ cssExports, fileName, logger, options, }: {
5+
cssExports: CSSExportsWithSourceMap;
6+
fileName: string;
7+
logger: Logger;
8+
options: Options;
9+
}) => string;

dist/helpers/createDtsExports.js

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
exports.createDtsExports = void 0;
4+
var source_map_js_1 = require("source-map-js");
5+
var classTransforms_1 = require("./classTransforms");
6+
var validVarRegexp_1 = require("./validVarRegexp");
7+
var isValidVariable = function (classname) {
8+
return validVarRegexp_1.VALID_VARIABLE_REGEXP.test(classname);
9+
};
10+
var flattenClassNames = function (previousValue, currentValue) {
11+
if (previousValue === void 0) { previousValue = []; }
12+
return previousValue.concat(currentValue);
13+
};
14+
var createDtsExports = function (_a) {
15+
var _b, _c;
16+
var cssExports = _a.cssExports, fileName = _a.fileName, logger = _a.logger, options = _a.options;
17+
var classes = cssExports.classes;
18+
var possiblyUndefined = Boolean(options.noUncheckedIndexedAccess);
19+
var classnameToProperty = function (classname) {
20+
return "'".concat(classname, "'").concat(possiblyUndefined ? '?' : '', ": string;");
21+
};
22+
var classnameToNamedExport = function (classname) {
23+
return "export let ".concat(classname, ": string").concat(possiblyUndefined ? ' | undefined' : '', ";");
24+
};
25+
var processedClasses = Object.keys(classes)
26+
.map((0, classTransforms_1.transformClasses)(options.classnameTransform))
27+
.reduce(flattenClassNames, []);
28+
var filteredClasses = processedClasses
29+
.filter(isValidVariable)
30+
.map(classnameToNamedExport);
31+
var dts = '';
32+
if (options.goToDefinition && cssExports.sourceMap) {
33+
// Create a new source map consumer.
34+
var smc_1 = new source_map_js_1.SourceMapConsumer(cssExports.sourceMap);
35+
// Split original CSS file into lines.
36+
var cssLines_1 = (_c = (_b = cssExports.css) === null || _b === void 0 ? void 0 : _b.split('\n')) !== null && _c !== void 0 ? _c : [];
37+
// Create new equal size array of empty strings.
38+
var dtsLines_1 = Array.from(Array(cssLines_1.length), function () { return ''; });
39+
// Create a list of filtered classnames and hashed classnames.
40+
var filteredClasses_1 = Object.entries(cssExports.classes)
41+
.map(function (_a) {
42+
var classname = _a[0], originalClassname = _a[1];
43+
return [
44+
// TODO: Improve this. It may return multiple valid classnames and we
45+
// want to handle all of those.
46+
(0, classTransforms_1.transformClasses)(options.classnameTransform)(classname)[0],
47+
originalClassname,
48+
];
49+
})
50+
.filter(function (_a) {
51+
var classname = _a[0];
52+
return isValidVariable(classname);
53+
});
54+
filteredClasses_1.forEach(function (_a) {
55+
var classname = _a[0], originalClassname = _a[1];
56+
var matchedLine;
57+
var matchedColumn;
58+
for (var i = 0; i < cssLines_1.length; i++) {
59+
var match = new RegExp(
60+
// NOTE: This excludes any match not starting with:
61+
// - `.` for classnames,
62+
// - `:` or ` ` for animation names,
63+
// and any matches followed by valid CSS selector characters.
64+
"[:.\\s]".concat(originalClassname, "(?![_a-zA-Z0-9-])"), 'g').exec(cssLines_1[i]);
65+
if (match) {
66+
matchedLine = i;
67+
matchedColumn = match.index;
68+
break;
69+
}
70+
}
71+
var lineNumber = smc_1.originalPositionFor({
72+
// Lines start at 1, not 0.
73+
line: matchedLine ? matchedLine + 1 : 1,
74+
column: matchedColumn ? matchedColumn : 0,
75+
}).line;
76+
dtsLines_1[lineNumber ? lineNumber - 1 : 0] +=
77+
classnameToNamedExport(classname);
78+
});
79+
dts = dtsLines_1.join('\n');
80+
}
81+
dts += "declare let _classes: {\n ".concat(processedClasses.map(classnameToProperty).join('\n ')).concat(options.allowUnknownClassnames ? '\n [key: string]: string;' : '', "\n};\nexport default _classes;\n");
82+
if (!options.goToDefinition &&
83+
options.namedExports !== false &&
84+
filteredClasses.length) {
85+
dts += filteredClasses.join('\n') + '\n';
86+
}
87+
if (options.customTemplate) {
88+
// eslint-disable-next-line @typescript-eslint/no-var-requires
89+
var customTemplate = require(options.customTemplate);
90+
return customTemplate(dts, {
91+
classes: classes,
92+
fileName: fileName,
93+
logger: logger,
94+
});
95+
}
96+
return dts;
97+
};
98+
exports.createDtsExports = createDtsExports;

dist/helpers/createMatchers.d.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { Options } from '../options';
2+
import { isCSSFn, isRelativeCSSFn } from './cssExtensions';
3+
import { Logger } from './logger';
4+
interface Matchers {
5+
isCSS: isCSSFn;
6+
isRelativeCSS: isRelativeCSSFn;
7+
}
8+
export declare const createMatchers: (logger: Logger, options?: Options) => Matchers;
9+
export {};

dist/helpers/createMatchers.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
exports.createMatchers = void 0;
4+
var cssExtensions_1 = require("./cssExtensions");
5+
var createMatchers = function (logger, options) {
6+
if (options === void 0) { options = {}; }
7+
// Allow custom matchers to be used, and handle bad matcher patterns.
8+
var isCSS = (0, cssExtensions_1.createIsCSS)();
9+
try {
10+
var customMatcher = options.customMatcher;
11+
if (customMatcher) {
12+
var customMatcherRegExp = new RegExp(customMatcher);
13+
isCSS = (0, cssExtensions_1.createIsCSS)(customMatcherRegExp);
14+
}
15+
}
16+
catch (e) {
17+
logger.error(e);
18+
// TODO: Provide error/warning to user.
19+
}
20+
// Create the relative CSS checker.
21+
var isRelativeCSS = (0, cssExtensions_1.createIsRelativeCSS)(isCSS);
22+
return { isCSS: isCSS, isRelativeCSS: isRelativeCSS };
23+
};
24+
exports.createMatchers = createMatchers;

dist/helpers/cssExtensions.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export type isCSSFn = (fileName: string) => boolean;
2+
export type isRelativeCSSFn = (fileName: string) => boolean;
3+
export declare const createIsCSS: (customMatcher?: RegExp) => isCSSFn;
4+
export declare const createIsRelativeCSS: (isCSS: isCSSFn) => isRelativeCSSFn;

dist/helpers/cssExtensions.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
exports.createIsRelativeCSS = exports.createIsCSS = void 0;
4+
var DEFAULT_REGEXP = /\.module\.(((c|le|sa|sc)ss)|styl)$/;
5+
var isRelative = function (fileName) { return /^\.\.?($|[\\/])/.test(fileName); };
6+
var createIsCSS = function (customMatcher) {
7+
if (customMatcher === void 0) { customMatcher = DEFAULT_REGEXP; }
8+
return function (fileName) {
9+
return customMatcher.test(fileName);
10+
};
11+
};
12+
exports.createIsCSS = createIsCSS;
13+
var createIsRelativeCSS = function (isCSS) {
14+
return function (fileName) {
15+
return isCSS(fileName) && isRelative(fileName);
16+
};
17+
};
18+
exports.createIsRelativeCSS = createIsRelativeCSS;

dist/helpers/filterPlugins.d.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { type AcceptedPlugin } from 'postcss';
2+
interface FilterPluginsOptions {
3+
plugins: AcceptedPlugin[];
4+
exclude?: string[];
5+
}
6+
export declare const filterPlugins: ({ plugins, exclude }: FilterPluginsOptions) => AcceptedPlugin[];
7+
export {};

dist/helpers/filterPlugins.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
exports.filterPlugins = void 0;
4+
var filterPlugins = function (_a) {
5+
var plugins = _a.plugins, exclude = _a.exclude;
6+
return exclude
7+
? plugins.filter(function (plugin) {
8+
return 'postcssPlugin' in plugin && !exclude.includes(plugin.postcssPlugin);
9+
})
10+
: plugins;
11+
};
12+
exports.filterPlugins = filterPlugins;

dist/helpers/getCssExports.d.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import Processor from 'postcss/lib/processor';
2+
import { CSSExports } from 'icss-utils';
3+
import { RawSourceMap } from 'source-map-js';
4+
import type tsModule from 'typescript/lib/tsserverlibrary';
5+
import { Options } from '../options';
6+
import { Logger } from './logger';
7+
export declare const enum FileType {
8+
css = "css",
9+
less = "less",
10+
sass = "sass",
11+
scss = "scss",
12+
styl = "styl"
13+
}
14+
export declare const getFileType: (fileName: string) => FileType;
15+
export interface CSSExportsWithSourceMap {
16+
classes: CSSExports;
17+
css?: string;
18+
sourceMap?: RawSourceMap;
19+
}
20+
export declare const getCssExports: ({ css, fileName, logger, options, processor, compilerOptions, directory, }: {
21+
css: string;
22+
fileName: string;
23+
logger: Logger;
24+
options: Options;
25+
processor: Processor;
26+
compilerOptions: tsModule.CompilerOptions;
27+
directory: string;
28+
}) => CSSExportsWithSourceMap;

0 commit comments

Comments
 (0)