Skip to content

Commit 4d55a9f

Browse files
authored
Merge pull request #3 from openlayers/forward-slashes
Always use forward slashes in module path
2 parents b40f868 + c59bdd0 commit 4d55a9f

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

index.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ if (!fs.existsSync(moduleRootAbsolute)) {
1818
const importRegEx = /import\(["']([^"']*)["']\)\.([^ \.\|\}><,\)=\n]*)([ \.\|\}><,\)=\n])/g;
1919
const typedefRegEx = /@typedef \{[^\}]*\} ([^ \r?\n?]*)/;
2020
const noClassdescRegEx = /@(typedef|module|type)/;
21+
const slashRegEx = /\\/g;
2122

2223
const moduleInfos = {};
2324
const fileNodes = {};
@@ -140,7 +141,7 @@ exports.astNodeVisitor = {
140141
const moduleId = path.relative(path.join(process.cwd(), moduleRoot), absolutePath).replace(/\.js$/, '');
141142
const exportName = identifier.defaultImport ? getDefaultExportName(moduleId, parser) : node.superClass.name;
142143
const delimiter = identifier.defaultImport ? '~' : getDelimiter(moduleId, exportName, parser);
143-
lines[lines.length - 2] = ' * @extends ' + `module:${moduleId}${exportName ? delimiter + exportName : ''}`;
144+
lines[lines.length - 2] = ' * @extends ' + `module:${moduleId.replace(slashRegEx, '/')}${exportName ? delimiter + exportName : ''}`;
144145
} else {
145146
lines[lines.length - 2] = ' * @extends ' + node.superClass.name;
146147
}
@@ -167,10 +168,10 @@ exports.astNodeVisitor = {
167168
replacement = `module:${importMatch[1]}${importMatch[2] === 'default' ? '' : '~' + importMatch[2]}`;
168169
} else {
169170
const rel = path.resolve(path.dirname(currentSourceName), importMatch[1]);
170-
const importModule = path.relative(path.join(process.cwd(), moduleRoot), rel).replace(/\.js$/, '');
171-
const exportName = importMatch[2] === 'default' ? getDefaultExportName(importModule, parser) : importMatch[2];
172-
const delimiter = importMatch[2] === 'default' ? '~': getDelimiter(importModule, exportName, parser);
173-
replacement = `module:${importModule}${exportName ? delimiter + exportName : ''}`;
171+
const moduleId = path.relative(path.join(process.cwd(), moduleRoot), rel).replace(/\.js$/, '');
172+
const exportName = importMatch[2] === 'default' ? getDefaultExportName(moduleId, parser) : importMatch[2];
173+
const delimiter = importMatch[2] === 'default' ? '~': getDelimiter(moduleId, exportName, parser);
174+
replacement = `module:${moduleId.replace(slashRegEx, '/')}${exportName ? delimiter + exportName : ''}`;
174175
}
175176
comment.value = comment.value.replace(importMatch[0], replacement + importMatch[3]);
176177
}
@@ -192,7 +193,7 @@ exports.astNodeVisitor = {
192193
const moduleId = path.relative(path.join(process.cwd(), moduleRoot), absolutePath).replace(/\.js$/, '');
193194
const exportName = identifier.defaultImport ? getDefaultExportName(moduleId, parser) : key;
194195
const delimiter = identifier.defaultImport ? '~' : getDelimiter(moduleId, exportName, parser);
195-
const replacement = `module:${moduleId}${exportName ? delimiter + exportName : ''}`;
196+
const replacement = `module:${moduleId.replace(slashRegEx, '/')}${exportName ? delimiter + exportName : ''}`;
196197
comment.value = comment.value.replace(regex, '$1' + replacement);
197198
}
198199
});

0 commit comments

Comments
 (0)