generated from Seekra/repository-template
feat(build): make permissions checks less strict
This commit is contained in:
+6
-1
@@ -17,7 +17,7 @@ limitations under the License.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { processPlugin } from './utils/plugin.js';
|
import { processPlugin } from './utils/plugin.js';
|
||||||
import { readdir } from 'node:fs/promises';
|
import { readdir, rm } from 'node:fs/promises';
|
||||||
import { join } from 'node:path';
|
import { join } from 'node:path';
|
||||||
import { pathToFileURL } from 'node:url';
|
import { pathToFileURL } from 'node:url';
|
||||||
import { parseArgs } from 'node:util';
|
import { parseArgs } from 'node:util';
|
||||||
@@ -47,6 +47,11 @@ const { values: args } = parseArgs({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
await rm(args.distBase, {
|
||||||
|
recursive: true,
|
||||||
|
force: true
|
||||||
|
});
|
||||||
|
|
||||||
(await Promise.all(
|
(await Promise.all(
|
||||||
files
|
files
|
||||||
.filter((file) => file.endsWith('.js'))
|
.filter((file) => file.endsWith('.js'))
|
||||||
|
|||||||
+7
-24
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { checkFileReadAccess, exists, isDirectory } from './fileAccess.js';
|
import { exists, isDirectory } from './fileAccess.js';
|
||||||
import { cp, mkdir, writeFile } from 'node:fs/promises';
|
import { cp, mkdir, writeFile } from 'node:fs/promises';
|
||||||
import { dirname, join } from 'node:path';
|
import { dirname, join } from 'node:path';
|
||||||
|
|
||||||
@@ -29,27 +29,7 @@ const validateArtifact = function validateArtifact (artifact) {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
} else if (artifact.type === 'copy') {
|
} else if (artifact.type === 'copy') {
|
||||||
if (typeof artifact.options.source !== 'string') return false;
|
return typeof artifact.options.source === 'string';
|
||||||
return checkFileReadAccess(artifact.options.source);
|
|
||||||
}
|
|
||||||
return valid;
|
|
||||||
};
|
|
||||||
|
|
||||||
const checkPath = async function checkPath (path) {
|
|
||||||
const directory = dirname(path);
|
|
||||||
if (await exists(directory) && !await isDirectory(directory)) {
|
|
||||||
console.warn('Skipping artifact as parent directory exists and is not a directory.');
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
if (!await exists(directory)) {
|
|
||||||
await mkdir(directory, { recursive: true });
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
} catch (err) {
|
|
||||||
console.warn('Skipping artifact as directory is not creatable.');
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -58,8 +38,11 @@ export const processArtifact = async function processArtifact (artifact, { srcBa
|
|||||||
console.warn('Skipping artifact as it is invalid.');
|
console.warn('Skipping artifact as it is invalid.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const distPath = join(distBase, artifact.path)
|
const distPath = join(distBase, artifact.path);
|
||||||
if (!await checkPath(distPath)) return;
|
const distPathDirectory = dirname(distPath);
|
||||||
|
if (!await exists(distPathDirectory)) {
|
||||||
|
await mkdir(distPathDirectory, { recursive: true });
|
||||||
|
}
|
||||||
if (artifact.type === 'text') {
|
if (artifact.type === 'text') {
|
||||||
await writeFile(
|
await writeFile(
|
||||||
distPath,
|
distPath,
|
||||||
|
|||||||
@@ -16,16 +16,6 @@ limitations under the License.
|
|||||||
|
|
||||||
import { access, constants, stat } from 'node:fs/promises';
|
import { access, constants, stat } from 'node:fs/promises';
|
||||||
|
|
||||||
export const checkFileReadAccess = async function checkFileWriteAccess (path) {
|
|
||||||
try {
|
|
||||||
await access(path, constants.F_OK | constants.R_OK);
|
|
||||||
return true;
|
|
||||||
} catch (err) {
|
|
||||||
if (err.code === 'ENOENT' || err.code === 'EACCES') return false;
|
|
||||||
else throw err;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
export const exists = async function exists (path) {
|
export const exists = async function exists (path) {
|
||||||
try {
|
try {
|
||||||
await access(path, constants.F_OK);
|
await access(path, constants.F_OK);
|
||||||
|
|||||||
Reference in New Issue
Block a user