Skip to content

Commit

Permalink
Prefixing classMap in autoloader correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
marekdedic committed Apr 29, 2024
1 parent dabc5ce commit d5fc733
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 105 deletions.
58 changes: 47 additions & 11 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
/* eslint-env node */

import { Transform } from 'node:stream';

import gulp from 'gulp';
import cleanCSS from 'gulp-clean-css';
import inject from 'gulp-inject-string';
import rename from 'gulp-rename';
import replace from 'gulp-replace';
import shell from 'gulp-shell';
import named from 'vinyl-named';
import webpack from 'webpack-stream';
Expand Down Expand Up @@ -45,16 +46,51 @@ gulp.task(
gulp
.src(['vendor/composer/autoload_static.php'])
.pipe(
replace(
'namespace Composer\\Autoload;',
'namespace Sgdg\\Vendor\\Composer\\Autoload;'
)
)
.pipe(
replace(
/'(.*)\\\\' => \n/g,
"'Sgdg\\\\Vendor\\\\$1\\\\' => \n"
)
new Transform({
objectMode: true,
transform: (chunk, encoding, callback) => {
let contents = String(chunk.contents).split('\n');
let mode = 'none';
contents = contents.map((line) => {
if (/^\s*\);$/g.exec(line)) {
mode = 'none';
} else if (
/^\s*public static \$prefixDirsPsr4 = array \($/.exec(
line
)
) {
mode = 'prefixDirs';
} else if (
/^\s*public static \$classMap = array \($/.exec(
line
)
) {
mode = 'classMap';
} else if (mode === 'prefixDirs') {
line = line.replace(
/^(\s*)'([^']*)\\\\' => $/,
"$1'Sgdg\\\\Vendor\\\\$2\\\\' => "
);
} else if (mode === 'classMap') {
line = line.replace(
/^(\s*)'([^']*)' =>/,
"$1'Sgdg\\\\Vendor\\\\$2' =>"
);
} else {
line = line.replace(
'namespace Composer\\Autoload;',
'namespace Sgdg\\Vendor\\Composer\\Autoload;'
);
}
return line;
});
chunk.contents = Buffer.from(
contents.join('\n'),
encoding
);
callback(null, chunk);
},
})
)
.pipe(gulp.dest('dist/vendor/composer/')),
shell.task('composer dump-autoload')
Expand Down
93 changes: 0 additions & 93 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@
"gulp-clean-css": "^4.3.0",
"gulp-inject-string": "^1.1.2",
"gulp-rename": "^2.0.0",
"gulp-replace": "^1.1.4",
"gulp-shell": "^0.8.0",
"npm-run-all": "^4.1.5",
"prettier": "^3.2.5",
Expand Down

0 comments on commit d5fc733

Please sign in to comment.