Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
svgString = svgString.replace(/(xlink:href="file:\/\/)([^"]*)(")/g, function(match, $1, $2, $3, offset, input_string) {
if (!config.directory) {
console.log("For svg node with id=" + config.id + " no image directory has been specified");
// Leave the local file path untouched, since we cannot load the specified image
return $1 + $2 + $3;
}
var fileName = $2;
var url = path.format({
root: '/ignored',
dir: config.directory,
base: fileName
});
if (!fs.existsSync(url)) {
console.log("The specified local image file (" + url + ") does not exist");
// Leave the local file path untouched, since we cannot load the specified image
return $1 + $2 + $3;
}
try {
var data = fs.readFileSync(url);
var contentType = mime.lookup(url);
function toPodsPath(base: string, templatePath: string, ext: string): string {
let pods = path.parse(templatePath);
delete pods.base; // Required for path.format to pick up new extension.
pods.name = "stylesheet";
pods.ext = `.block.${ext}`;
return path.join(base, path.format(pods));
}
// Start dashboard client production server
dashboardClientServer({
serverPort: dashboardServerPort,
clientPort: dashboardClientPort,
staticRootPath: path.join(pri.projectRootPath, tempPath.dir, 'static'),
hash: projectState.get('dashboardHash'),
});
// Serve project
await runWebpackDevServer({
mode: 'development',
autoOpenBrowser: true,
hot: pri.sourceConfig.hotReload,
publicPath: globalState.sourceConfig.publicPath,
entryPath: path.join(globalState.projectRootPath, path.format(tempJsEntryPath)),
devServerPort: freePort,
htmlTemplatePath: path.join(__dirname, '../../../../template-project.ejs'),
htmlTemplateArgs: {
dashboardServerPort,
},
pipeConfig,
});
}
}
path = rewriteDir(path)
const ignored = IGNORE.some(ignore => {
ignore = join('/', ignore, '/')
return path.substr(0, ignore.length) == ignore
})
const convert = EXTS.includes(extname(path))
if (!ignored && convert) {
const exts = EXTS.filter(ext => ext != extname(path))
for (const ext of [extname(path), ...exts]) {
const {dir, name} = parse(path)
const file = format({dir, name, ext})
const mtime = await stat(join(ROOT, file))
.then(stats => (stats.isFile() ? stats.mtime : undefined))
.catch(() => undefined)
if (mtime) {
const entry = CACHE.get(file)
res.setHeader('Content-Type', 'text/javascript')
if (entry && +entry.mtime == +mtime) {
if (VERBOSE) console.log('200', file, '(cache)')
return res.end(entry.code)
}
else {
const result = await transformFileAsync(join(ROOT, file), {
plugins: [[require('babel-plugin-bare-import-rewrite'), {extensions: EXTS}]],
cwd: ROOT,
})
if (!result) throw new Error('Babel transformation failed')
_createInfoFile(item, dir) {
fs.writeFileSync(path.format({ dir, base: getFileName(filesConst.INFO_FILE) }), JSON.stringify(item));
}
_createConfigFile(dir, data, type, key) {
function getSnapshotPath(testPath) {
const testPathParsed = path.parse(testPath);
testPathParsed.dir = path.join(testPathParsed.dir, '__snapshots__');
testPathParsed.base = testPathParsed.name + '.unexpected-snap';
return path.format(testPathParsed);
}
const addFilenameSuffix = (relativePath, suffix) => {
const pathInfo = path.parse(relativePath);
return path.format({
dir: pathInfo.dir,
name: pathInfo.name + '-' + suffix,
ext: pathInfo.ext,
});
};
.pipe(through2.obj((file, enc, cb) => {
const rawPkg = JSON.parse(file.contents);
rawPkg.engines = pkg.engines;
rawPkg.license = pkg.license;
rawPkg.author = pkg.author;
rawPkg.repository = pkg.repository;
rawPkg.dependencies = applyVersions(rawPkg.dependencies);
rawPkg.devDependencies = applyVersions(rawPkg.devDependencies);
cb(null, Object.assign(file, {
contents: new Buffer(JSON.stringify(rawPkg)),
path: path.format(Object.assign(path.parse(file.path), {
base: 'package.json'
}))
}));
}))
.pipe(gulp.dest('./packages'))
function classifyFiles (filename) {
const relPath = path.normalize(
path.relative(appPath, filename)
)
if (path.relative(filename, entryFilePath) === '') return FILE_TYPE.ENTRY
let relSrcPath = path.relative('src', relPath)
relSrcPath = path.format({
dir: path.dirname(relSrcPath),
base: path.basename(relSrcPath, path.extname(relSrcPath))
})
const isPage = pages.some(page => {
const relPage = path.normalize(
path.relative(appPath, page)
)
if (path.relative(relPage, relSrcPath) === '') return true
})
if (isPage) {
return FILE_TYPE.PAGE
} else {
return FILE_TYPE.NORMAL
}
}
}
if (options.strip === true) {
file.name = strip.increment(file.name, options);
file.dir = strip.increment(file.dir, options);
file.base = file.name + file.ext;
}
if (options.fs === true) {
let name = file.name;
let dest = path.format(file);
while (fs.existsSync(dest)) {
file.base = fn(name, start++) + file.ext;
dest = path.format(file);
}
} else {
file.base = fn(file.name, start) + file.ext;
}
file.path = path.join(file.dir, file.base);
return file;
};