From ec18ff45a7dc4d65e11281c1d2b50d955fdb8f0f Mon Sep 17 00:00:00 2001 From: Jonathan Cammisuli Date: Fri, 16 Jun 2023 21:53:52 -0400 Subject: [PATCH] feat(core): require native code in function blocks rather than top level --- packages/nx/src/tasks-runner/cache.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/nx/src/tasks-runner/cache.ts b/packages/nx/src/tasks-runner/cache.ts index 888bc08b9a94a7..fa3ed46fa2fd7d 100644 --- a/packages/nx/src/tasks-runner/cache.ts +++ b/packages/nx/src/tasks-runner/cache.ts @@ -5,7 +5,6 @@ import { DefaultTasksRunnerOptions } from './default-tasks-runner'; import { spawn } from 'child_process'; import { cacheDir } from '../utils/cache-directory'; import { Task } from '../config/task-graph'; -import { copy, expandOutputs, remove } from '../native'; export type CachedResult = { terminalOutput: string; @@ -72,7 +71,7 @@ export class Cache { const tdCommit = join(this.cachePath, `${task.hash}.commit`); // might be left overs from partially-completed cache invocations - await remove(tdCommit); + await this.remove(tdCommit); await this.remove(td); await mkdir(td); @@ -153,6 +152,7 @@ export class Cache { outputs: string[], cwd: string ): Promise { + const { expandOutputs } = require('../native'); performance.mark('expandOutputs:start'); const results = expandOutputs(cwd, outputs); performance.mark('expandOutputs:end'); @@ -166,6 +166,7 @@ export class Cache { } private async copy(src: string, destination: string): Promise { + const { copy } = require('../native'); // 'cp -a /path/dir/ dest/' operates differently to 'cp -a /path/dir dest/' // --> which means actual build works but subsequent populate from cache (using cp -a) does not // --> the fix is to remove trailing slashes to ensure consistent & expected behaviour @@ -182,6 +183,7 @@ export class Cache { } private async remove(path: string): Promise { + const { remove } = require('../native'); return new Promise((res, rej) => { try { remove(path);