Skip to content

Commit

Permalink
feat: remove all deps and use one bundle
Browse files Browse the repository at this point in the history
  • Loading branch information
anthony-redFox committed Nov 16, 2021
1 parent 620470f commit 4ec2e86
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 48 deletions.
22 changes: 22 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
"ini": "^2.0.0",
"jest": "^27.3.1",
"js-yaml": "^4.1.0",
"json-schema": "^0.3.0",
"konan": "^2.1.1",
"lint-staged": "^11.1.2",
"lodash": "^4.17.21",
"json-schema": "^0.3.0",
"lint-staged": "^11.1.2",
Expand All @@ -55,11 +58,12 @@
"remark-html": "^15.0.0",
"remark-reference-links": "^6.0.0",
"remark-toc": "^8.0.1",
"konan": "^2.1.1",
"resolve": "^1.20.0",
"rollup": "^2.58.0",
"standard-version": "^9.3.2",
"strip-json-comments": "^4.0.0",
"tiny-glob": "^0.2.9",
"tmp": "^0.2.1",
"unist-builder": "^3.0.0",
"tmp": "^0.2.1",
"unist-util-visit": "^4.1.0",
Expand Down
3 changes: 1 addition & 2 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ export default {
'node:fs',
'fs/promises',
'@vue/compiler-sfc',
'vue-template-compiler',
'glob'
'vue-template-compiler'
],
plugins: [
nodeResolve({ exportConditions: ['node', 'default', 'module', 'require'] }),
Expand Down
3 changes: 2 additions & 1 deletion src/input/dependency.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ export default async function dependencyStream(
indexes,
{ parseExtension = [], requireExtension = [] }
) {
const md = await mdeps(smartGlob(indexes, parseExtension), {
const inputs = await smartGlob(indexes, parseExtension);
const md = await mdeps(inputs, {
/**
* Determine whether a module should be included in documentation
* @param {string} id path to a module
Expand Down
2 changes: 1 addition & 1 deletion src/input/moduleDeps.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,5 +104,5 @@ class Deps {

export default async function (input = [], opts = {}) {
const dep = new Deps(opts);
return dep.flush(Array.from(new Set(input)));
return dep.flush(input);
}
4 changes: 3 additions & 1 deletion src/input/shallow.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ export default async function (indexes, config) {
return typeof v === 'string';
});
const files = await Promise.all(
smartGlob(paths, config.parseExtension).map(async file => ({
(
await smartGlob(paths, config.parseExtension)
).map(async file => ({
source: await readFileCode(file),
file
}))
Expand Down
63 changes: 21 additions & 42 deletions src/input/smart_glob.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fs from 'fs';
import path from 'path';
import glob from 'glob';
import glob from 'tiny-glob';

/**
* Replace Windows with posix style paths
Expand Down Expand Up @@ -30,20 +30,17 @@ function convertPathToPosix(filepath) {
* matches all files with the provided extensions if
* pathname is a directory.
*/
function processPath(extensions) {
function processPath(extensions = ['.js']) {
const cwd = process.cwd();
extensions = extensions || ['.js'];

extensions = extensions.map(function (ext) {
return ext.replace(/^\./, '');
});
extensions = extensions.map(ext => ext.replace(/^\./, ''));

let suffix = '/**';
let suffix = '/**/*.';

if (extensions.length === 1) {
suffix += '/*.' + extensions[0];
suffix += extensions[0];
} else {
suffix += '/*.{' + extensions.join(',') + '}';
suffix += `{${extensions.join(',')}}`;
}

/**
Expand Down Expand Up @@ -79,51 +76,33 @@ function resolveFileGlobPatterns(patterns, extensions) {
return patterns.map(processPathExtensions);
}

const cwd = process.cwd();
const globOptions = {
filesOnly: true,
dot: true,
cwd
};

/**
* Build a list of absolute filenames on which ESLint will act.
* Ignored files are excluded from the results, as are duplicates.
*
* @param globPatterns Glob patterns.
* @returns Resolved absolute filenames.
*/
function listFilesToProcess(globPatterns) {
const files = [];
const added = new Set();

const cwd = process.cwd();

/**
* Executes the linter on a file defined by the `filename`. Skips
* unsupported file extensions and any files that are already linted.
* @param {string} filename The file to be processed
* @returns {void}
*/
function addFile(filename) {
if (added.has(filename)) {
return;
}
files.push(filename);
added.add(filename);
}

globPatterns.forEach(function (pattern) {
async function listFilesToProcess(globPatterns) {
const promises = globPatterns.map(async pattern => {
const file = path.resolve(cwd, pattern);
if (fs.existsSync(file) && fs.statSync(file).isFile()) {
addFile(fs.realpathSync(file));
} else {
const globOptions = {
nodir: true,
dot: true,
cwd
};

glob.sync(pattern, globOptions).forEach(function (globMatch) {
addFile(path.resolve(cwd, globMatch));
});
return fs.realpathSync(file);
}
return (await glob(pattern, globOptions)).map(globMatch =>
path.resolve(cwd, globMatch)
);
});

return files;
const files = (await Promise.all(promises)).flat();
return Array.from(new Set(files));
}

export default function smartGlob(indexes, extensions) {
Expand Down

0 comments on commit 4ec2e86

Please sign in to comment.