fix(providence): improve perf by memoization
This commit is contained in:
parent
621671a424
commit
30122f0e31
2 changed files with 16 additions and 13 deletions
|
|
@ -8,10 +8,10 @@ const { LogService } = require('../program/services/LogService.js');
|
||||||
const JsdocCommentParser = require('../program/utils/jsdoc-comment-parser.js');
|
const JsdocCommentParser = require('../program/utils/jsdoc-comment-parser.js');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @desc extracts name, defaultValue, optional, type, desc from JsdocCommentParser.parse method
|
* Extracts name, defaultValue, optional, type, desc from JsdocCommentParser.parse method
|
||||||
* result
|
* result
|
||||||
* @param {array} jsdoc
|
* @param {string[]} jsdoc
|
||||||
* @returns {object}
|
* @returns {{ name:string, defaultValue:string, optional:boolean, type:string, desc:string }}
|
||||||
*/
|
*/
|
||||||
function getPropsFromParsedJsDoc(jsdoc) {
|
function getPropsFromParsedJsDoc(jsdoc) {
|
||||||
const jsdocProps = jsdoc.filter(p => p.tagName === '@property');
|
const jsdocProps = jsdoc.filter(p => p.tagName === '@property');
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@
|
||||||
const pathLib = require('path');
|
const pathLib = require('path');
|
||||||
const { nodeResolve } = require('@rollup/plugin-node-resolve');
|
const { nodeResolve } = require('@rollup/plugin-node-resolve');
|
||||||
const { LogService } = require('../services/LogService.js');
|
const { LogService } = require('../services/LogService.js');
|
||||||
|
const { memoizeAsync } = require('./memoize.js');
|
||||||
|
|
||||||
const fakePluginContext = {
|
const fakePluginContext = {
|
||||||
meta: {
|
meta: {
|
||||||
|
|
@ -27,15 +28,6 @@ const fakePluginContext = {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Based on importee (in a statement "import {x} from '@lion/core'", "@lion/core" is an
|
|
||||||
* importee), which can be a bare module specifier, a filename without extension, or a folder
|
|
||||||
* name without an extension.
|
|
||||||
* @param {SpecifierSource} importee source like '@lion/core' or '../helpers/index.js'
|
|
||||||
* @param {PathFromSystemRoot} importer importing file, like '/my/project/importing-file.js'
|
|
||||||
* @param {{customResolveOptions?: {preserveSymlinks:boolean}}} [opts] nodeResolve options
|
|
||||||
* @returns {Promise<PathFromSystemRoot|null>} the resolved file system path, like '/my/project/node_modules/@lion/core/index.js'
|
|
||||||
*/
|
|
||||||
async function resolveImportPath(importee, importer, opts = {}) {
|
async function resolveImportPath(importee, importer, opts = {}) {
|
||||||
const rollupResolve = nodeResolve({
|
const rollupResolve = nodeResolve({
|
||||||
rootDir: pathLib.dirname(importer),
|
rootDir: pathLib.dirname(importer),
|
||||||
|
|
@ -62,4 +54,15 @@ async function resolveImportPath(importee, importer, opts = {}) {
|
||||||
return result.id;
|
return result.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = { resolveImportPath };
|
/**
|
||||||
|
* Based on importee (in a statement "import {x} from '@lion/core'", "@lion/core" is an
|
||||||
|
* importee), which can be a bare module specifier, a filename without extension, or a folder
|
||||||
|
* name without an extension.
|
||||||
|
* @param {SpecifierSource} importee source like '@lion/core' or '../helpers/index.js'
|
||||||
|
* @param {PathFromSystemRoot} importer importing file, like '/my/project/importing-file.js'
|
||||||
|
* @param {{customResolveOptions?: {preserveSymlinks:boolean}}} [opts] nodeResolve options
|
||||||
|
* @returns {Promise<PathFromSystemRoot|null>} the resolved file system path, like '/my/project/node_modules/@lion/core/index.js'
|
||||||
|
*/
|
||||||
|
const resolveImportPathMemoized = memoizeAsync(resolveImportPath);
|
||||||
|
|
||||||
|
module.exports = { resolveImportPath: resolveImportPathMemoized };
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue