fix: swallow an error in case symlink has already been created
This commit is contained in:
parent
3c0ac8105b
commit
699838c478
1 changed files with 18 additions and 8 deletions
|
|
@ -7,7 +7,7 @@ const NODE_MODULES_PATH = '/node_modules';
|
||||||
const NODE_MODULES_LION_DOCS = '_lion_docs';
|
const NODE_MODULES_LION_DOCS = '_lion_docs';
|
||||||
const require = createRequire(import.meta.url);
|
const require = createRequire(import.meta.url);
|
||||||
const DEBUG = 1;
|
const DEBUG = 1;
|
||||||
const DEBUG_COMPONENT = 'extend-a-native-input';
|
const DEBUG_COMPONENTS = ['extend-a-native-input', 'combobox/overview'];
|
||||||
const SHOW_MODULE_NOT_FOUND = false;
|
const SHOW_MODULE_NOT_FOUND = false;
|
||||||
|
|
||||||
const resolveLionImport = moduleResolvedPath => {
|
const resolveLionImport = moduleResolvedPath => {
|
||||||
|
|
@ -26,6 +26,11 @@ const resolveLionImport = moduleResolvedPath => {
|
||||||
return moduleResolvedPath.split(NODE_MODULES_PATH)[1];
|
return moduleResolvedPath.split(NODE_MODULES_PATH)[1];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const getLog = input =>
|
||||||
|
DEBUG && DEBUG_COMPONENTS.some(DEBUG_COMPONENT => input.includes(DEBUG_COMPONENT))
|
||||||
|
? console.log.bind(console)
|
||||||
|
: () => {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {string} source
|
* @param {string} source
|
||||||
* @param {string} inputPath
|
* @param {string} inputPath
|
||||||
|
|
@ -36,8 +41,8 @@ async function processImports(source, inputPath) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// for the debug purposes
|
// for the debug purposes
|
||||||
const log = DEBUG && inputPath.includes(DEBUG_COMPONENT) ? console.log.bind(console) : () => {};
|
const log = getLog(inputPath);
|
||||||
|
log('*** input path', inputPath);
|
||||||
let newSource = '';
|
let newSource = '';
|
||||||
let lastPos = 0;
|
let lastPos = 0;
|
||||||
await init;
|
await init;
|
||||||
|
|
@ -47,7 +52,7 @@ async function processImports(source, inputPath) {
|
||||||
|
|
||||||
const importSrc = source.substring(importObj.s, importObj.e);
|
const importSrc = source.substring(importObj.s, importObj.e);
|
||||||
try {
|
try {
|
||||||
log('path to resolve', importSrc);
|
log('*** path to resolve', importSrc);
|
||||||
let resolvedImportFullPath = importSrc;
|
let resolvedImportFullPath = importSrc;
|
||||||
if (importSrc.startsWith('.')) {
|
if (importSrc.startsWith('.')) {
|
||||||
const resolvedPath = require.resolve(importSrc, { paths: [path.dirname(inputPath)] });
|
const resolvedPath = require.resolve(importSrc, { paths: [path.dirname(inputPath)] });
|
||||||
|
|
@ -56,8 +61,12 @@ async function processImports(source, inputPath) {
|
||||||
if (!fs.existsSync(relativePath)) {
|
if (!fs.existsSync(relativePath)) {
|
||||||
log('does not exist, going to create', path.dirname(relativePath));
|
log('does not exist, going to create', path.dirname(relativePath));
|
||||||
// to be able to serve the files from the docs folder, we need to move them to /node_modules
|
// to be able to serve the files from the docs folder, we need to move them to /node_modules
|
||||||
|
try {
|
||||||
await fs.promises.mkdir(path.dirname(relativePath), { recursive: true });
|
await fs.promises.mkdir(path.dirname(relativePath), { recursive: true });
|
||||||
await fs.promises.symlink(resolvedPath, relativePath);
|
await fs.promises.symlink(resolvedPath, relativePath);
|
||||||
|
} catch (err) {
|
||||||
|
// symlink can already be there, do nothing
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
resolvedImportFullPath = `${NODE_MODULES_PATH}${resolvedLionImport}`;
|
resolvedImportFullPath = `${NODE_MODULES_PATH}${resolvedLionImport}`;
|
||||||
|
|
@ -84,6 +93,7 @@ async function processImports(source, inputPath) {
|
||||||
|
|
||||||
newSource += resolvedImportFullPath;
|
newSource += resolvedImportFullPath;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
if (SHOW_MODULE_NOT_FOUND && error.code === 'MODULE_NOT_FOUND') {
|
if (SHOW_MODULE_NOT_FOUND && error.code === 'MODULE_NOT_FOUND') {
|
||||||
console.error(`Error resolving import: ${importSrc}`, error);
|
console.error(`Error resolving import: ${importSrc}`, error);
|
||||||
}
|
}
|
||||||
|
|
@ -106,8 +116,8 @@ export function remarkProcessDemos() {
|
||||||
*/
|
*/
|
||||||
async function transformer(tree, file) {
|
async function transformer(tree, file) {
|
||||||
// throw new Error('no transformer');
|
// throw new Error('no transformer');
|
||||||
const log =
|
const log = getLog(file.history[0]);
|
||||||
DEBUG && file.history[0].includes(DEBUG_COMPONENT) ? console.log.bind(console) : () => {};
|
|
||||||
log(tree, file.data.frontmatter);
|
log(tree, file.data.frontmatter);
|
||||||
const { setupJsCode } = file.data;
|
const { setupJsCode } = file.data;
|
||||||
if (!setupJsCode) {
|
if (!setupJsCode) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue